orm.with_polymorphic() does not load columns of descendant classes
Issue #3158
resolved
Hi,
The documentation of orm.with_polymorphic() says:
Using this method will ensure that each descendant mapper’s tables are included in the FROM clause, and will allow filter() criterion to be used against those tables. The resulting instances will also have those columns already loaded so that no “post fetch” of those columns will be required.
However, that does not seem to be the case in the attached example - the subquery does load b.prop, but the top level query does not, so accessing it still generates an extra query.
Comments (3)
-
repo owner -
repo owner - changed status to resolved
added a doc note in b35e6c69b726d445a2d and ported to 1.0, 0.9, 0.8
-
reporter Ok, that makes sense, thanks.
- Log in to comment
an advanced case, needs to be called like this:
an example using joinedload() is at: http://docs.sqlalchemy.org/en/rel_0_9/orm/inheritance.html#eager-loading-of-specific-or-polymorphic-subtypes.
if you're on 0.8, the A_Alias needs "aliased=True" to work, 0.9 can navigate around this better.