I have a query like
(session.query(Root).with_polymorphic('*')
.outerjoin(Subclass.related1).options(contains_eager(Subclass.related1)))
So far things work.
I want also want to eagerly load Related1.related2
and I tried this:
(session.query(Root).with_polymorphic('*')
.outerjoin(Subclass.related1).options(contains_eager(Subclass.related1))
.outerjoin(Related1.related2).options(contains_eager(Related1.related2)))
But it doesn't work:
sqlalchemy.exc.ArgumentError: Can't find property 'related2' on any entity specified in this Query. Note the full path from root (Mapper|Root|root) to target entity must be specified.
Given that related1
is related to the root entity via a subclass I don't see how to specify the full path.
I also tried
(session.query(Root).with_polymorphic('*')
.outerjoin(Subclass.related1).options(contains_eager(Subclass.related1))
.outerjoin(Related1.related2).options(contains_eager('related1.related2')))
which predictably fails with
sqlalchemy.exc.ArgumentError: Can't find property named 'related1' on the mapped entity Mapper|Root|root in this Query.
How can I specify the full path to the indirectly-related entity in contains_eager()
?
contains_eager needs a full path from the entities the query knows about:
contains_eager(Subclass.related1, Related1.related2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With