Because I also want to be able to go the other way. I want to be able to 
get the a attribute from any given F. 

On Tuesday, March 24, 2015 at 4:47:42 PM UTC-7, Michael Bayer wrote:
>
>
>
> Andrew Millspaugh <[email protected] <javascript:>> wrote: 
>
> > 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. 
>
> If that’s all you need, why not put an accessor on F? 
>
> class F(Base): 
>     # … 
>
>    @classmethod 
>    def join_to_a(cls): 
>         return (F.e, E.d, D.c, C.b, B.a) 
>
>
> then: 
>
> F.query.join(*F.join_to_a()) 
>
>
>
>
>
> > 
> > On Tuesday, March 24, 2015 at 6:28:31 AM UTC-7, Michael Bayer wrote: 
> > 
> > 
> > Andrew Millspaugh <[email protected]> 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 [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/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 [email protected] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <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 [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/d/optout.

Reply via email to