Yes, I got the style from there. I have a great great great great grandchild that I need to be able to access by the great great great great grandparent id. How would you recommend doing that, then? I don't want to have to write f_instances = F.query.join(F.e).join(E.d).join(D.c).join(C.b).join(B.a).filter(A.id == 1).all() just to find the F's that have A.id 1.
On Tuesday, March 24, 2015 at 6:28:31 AM UTC-7, Michael Bayer wrote: > > > > Andrew Millspaugh <millspau...@gmail.com <javascript:>> wrote: > > > I've got a class hierarchy that looks something like this: > > > > [ A ] 1--------* [ B ] 1---------* [ C ] 1----------* [ D ] > 1--------0..1 [ E ] 1..*----------0..1 [ F ] > > > > org proj ticket snap > bidlimit ticketset > > > > And I'm trying to add a relationship from A to F with a backref. The > relationship definition (on the A model) looks like: > > > > f = DB.relationship('F', > > secondary=( > > 'join(F, E, F.id == E.f_id)' > > '.join(D, E.d_id == D.id)' > > '.join(C, D.c_id == C.id)' > > '.join(B, C.b_id == B.id)' > > ), > > primaryjoin='A.id == B.a_id', > > secondaryjoin='E.f_id == F.id', > > backref=DB.backref('a', uselist=False), viewonly=True > > ) > > > > Now, if I query A.f, I get all of the F's, instead of just the ones > which have a relationship with A. I'm sure I'm missing something simple, > but I can't seem to find it... Any help out there? > > what does your SQL output say? Is this query(A).join(A.f) or the “f” > attribute on an existing “A”? I’m assuming you got this style from > > http://docs.sqlalchemy.org/en/rel_0_9/orm/join_conditions.html#composite-secondary-joins, > > > note that its experimental and not well supported. In most cases you > should > deal with individual relationships between each class. > > > -- > > 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 sqlalchemy+...@googlegroups.com <javascript:>. > > To post to this group, send email to sqlal...@googlegroups.com > <javascript:>. > > Visit this group at http://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. > -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.