On 04/04/2016 07:35 PM, Jonathan Vanasco wrote:
I've been battling with a particular relationship and eventually managed
to get it working based off the docs when I realized I had a similar way
to short-circuit the chain, however I'm not happy with the result.
  (https://gist.github.com/jvanasco/6a98b339771bdee38e5d77b0da6ffd98)

My unhappiness is that I had to use the `foreign()`construct simply
because I couldn't figure out how to do a join:

        cs =relationship("C", secondary="join(A2B, C, A2B.b_id == C.b_id)"

        
        ,primaryjoin="and_(A.id == A2B.a_id)"
        ,secondaryjoin="C.b_id == foreign(A2B.b_id)",
        )




I was hoping to avoid the `foreign` and somehow do a straight join of:
     A.id == A2B.a_id,
     A2B.id == B.id,
     B.id == C.b_id

This query does what I want and is probably faster, I just have no idea
how to do things the other way.

i think the problem is that if you aren't nesting the JOIN and instead doing an implicit join, then things like joined eager loading don't work out as well. There's no subqueries in your primaryjoin I doubt there's a difference in speed.




Does anyone have deeper insight?  I spent about 2 hours on the docs
trying to really understand this section, and every time I thought I
understood -- I didn't.

--
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
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to