SQLAlchemy - order_by on relationship for join table

后端 未结 3 1606
灰色年华
灰色年华 2021-02-12 20:24

I\'m using declarative SQLAlchemy and I have three models: Role, Permission, and RolePermission. In my Role model, I have t

3条回答
  •  没有蜡笔的小新
    2021-02-12 20:51

    What you want is to order the role attribute of the RolePermission object. Passing order_by sets the order in the Role class.

    Try this:

    from sqlalchemy.orm import backref
    
    permissionLinks = relationship(RolePermission, backref=backref("role", order_by=name))
    

    setting an order for the back reference

提交回复
热议问题