Re: [Sqlalchemy-tickets] [sqlalchemy] #2762: Relationship lazy configuration doesn't work with poly
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-06-20 19:05:40
|
#2762: Relationship lazy configuration doesn't work with polymorphism
-----------------------------------+------------------------------------
Reporter: schlamar | Owner: zzzeek
Type: defect | Status: closed
Priority: medium | Milestone:
Component: orm | Severity: no triage selected yet
Resolution: worksforme | Keywords:
Progress State: completed/closed |
-----------------------------------+------------------------------------
Changes (by zzzeek):
* status: new => closed
* resolution: => worksforme
* status_field: awaiting triage => completed/closed
Comment:
a polymorphic load on joined table inheritance by default only loads from
the base table, not any of the related tables. therefore a joined eager
load from SubModel->related_model is ignored here.
The solution here is to use `with_polymorphic`, of which there are three
ways to specify (mapper level, `query.with_polymorphic()`, and the newer
`with_polymorphic()` standalone function), specifying that loads for
`Model` should also join out to load submodels of type `SubModel`:
{{{
#!python
session = Session()
model_with_related = with_polymorphic(Model, SubModel)
s = session.query(model_with_related).one()
session.close()
s.related_model
# or
session = Session()
s = session.query(Model).with_polymorphic(SubModel).one()
session.close()
s.related_model
# or
Model.__mapper__.with_polymorphic = (SubModel, None)
}}}
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2762#comment:1>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|