Apologies if I'm missing this is the docs somewhere, but I can't figure it
out. Suppose I have a many-to-many relationship between A and B, and that
I'd like have the various B's that a particular A points to ordered by
B.ordinal (i.e. in the examples below, I'd like A.bs to be sorted to
B.order). I can't figure out how to do that. I tried the following:
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
bs = association_proxy("a_to_b", "b", creator=lambda x: A_to_B(b=x))
class B(Base):
__tablename__ = 'b'
id = Column(Integer, primary_key=True)
order = Column(Integer)
class A_to_B(Base):
a_id = Column(Integer, ForeignKey(str(A.__table__) + ".id"),
nullable=False, index=True)
b_id = Column(Integer, ForeignKey(str(B.__table__) + ".id"),
nullable=False)
b = relationship(B, foreign_keys=[b_id])
a = relationship(A, foreign_keys=[a_id],
backref=backref("a_to_b", lazy="subquery",
cascade="all, delete-orphan", order_by=b.ordinal))
def __init__(self, a=None, b=None):
self.a = a
self.b = b
but get an error message:
AttributeError: 'RelationshipProperty' object has no attribute 'ordinal'
Is it possible to combine an association_proxy with an order_by clause?
Thanks!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.