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].
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