i have roughly the following model: Widget > Widget2Foo > Foo > Foo2Bar > Bar wherein `Foo` has multiple relationships to `Bar` (via a filter )
the setup works for lazyloading and subqueryloading, but I can't do multiple joinedloads:
eg:
lazyloading and this subquery works:
query = s.query(Widget)\
.options(joinedload('to_foos').joinedload('foo').joinedload('to_bars').joinedload('bar'))\
.options(subqueryload('to_foos.foo.to_bars_special.bar'))
but this won't work, because sqlalchemy has issues with the final segment
query = s.query(Widget)\
.options(joinedload('to_foos').joinedload('foo').joinedload('to_bars').joinedload('bar'))\
.options(joinedload('to_foos').joinedload('foo').joinedload('to_bars_special').joinedload('bar'))
i included the relevant bits below and can make a repeatable if needed .
i've traced the issue to the orm having issues with the the multiple joins to the same table -- so I figure i'm either pushing the limits or implemented that last relationship wrong and this will be obvious to someone with more experience.
---
class Foo(Base):
__tablename__ = 'foo'
id = Column(Integer, primary_key=True)
to_bars = relationship("Foo2Bar",
primaryjoin="""Foo.id==Foo2Bar.foo_id""",
)
to_bars_special = relationship("Foo2Bar",
primaryjoin="""and_(Foo.id==Foo2Bar.foo_id,
Foo2Bar.bar_id==Bar.id,
Bar.is_special==True,
)""",
)
class Bar(Base):
__tablename__ = 'bar'
id = Column(Integer, primary_key=True)
is_special = Column(Boolean, nullable=True)
class Foo2Bar(Base):
__tablename__ = 'foo2bar'
__primarykey__ = ['foo_id', 'bar_id']
foo_id = Column(Integer, ForeignKey("Foo.id"), primary_key=True)
bar_id = Column(Integer, ForeignKey("Bar.id"), primary_key=True)