I\'m using declarative SQLAlchemy and I have three models: Role
, Permission
, and RolePermission
. In my Role
model, I have t
The problem is in permissionLinks
relationship. Ordering its items by by Role.name
makes no sense to me.
I couldn't make any of these solutions work, however I found an easier way.
from sqlalchemy.ext.declarative import declarative_base
class User(Base):
# ....
addresses = relationship("Address",
order_by="desc(Address.email)",
primaryjoin="Address.user_id==User.id")
Found here: http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/relationships.html
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