Hey folks, I am looking for a bit of advice.  I have a many-to-many 
relationship which goes through a middle class:

class Foo(Base):
    id = Column(Integer, primary_key=True)

class Bar(Base):
    id = Column(Integer, primary_key=True)

class FooToBar(Base):
    foo_id = Column(Integer, primary_key=True, ForeignKey("foo.id"))
    bar_id = Column(Integer, primary_key=True, ForeignKey("bar.id")) 

I want to be able to eagerly-load a tree from a Foo to all its Bars, or a 
tree from a Bar to all its Foos, but I do not want to eagerly-load the 
entire graph of related Foo and Bar objects.  If I naively set up the 
relationship, that is what happens:

FooToBar.foo = relationship(Foo, backref="bars", lazy="joined")
FooToBar.bar = relationship(Bar, backref="foos", lazy="joined") 

Is there a straightforward way to accomplish tree-like loading?  (My actual 
code masks the existence of FooToBar with two association_proxy attributes, 
but I don't think that is relevant for the example.)  Could I generate 
two different models (in place of FooToBar), each with a one-way 
eager-loading relationship?  Or could I use join_depth on the relationship 
to cap how far the recursion goes?

Thanks,
Chris

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/tSDOeiYU4_0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to