On Apr 3, 2008, at 4:37 PM, Chris Guin wrote:
>
> eagerload() appears not to work when employed on queries to classes
> that have subclasses using joined table inheritance. I found a
> thread suggesting that, for such cases, contains_eager() would be
> better, although you have to build the statement yourself from which
> to query.
>
> When my table structure was simpler, this worked perfectly. But I
> have since added a new base class from which pretty much all of the
> other tables inherit, with the result that, when I use contains_eager
> to load a "sensor" into a "detection" (a detection has-a sensor, but
> both sensor and detection inherit from clips_object), SQLAlchemy
> loads a copy of the detection object itself into the "sensor" slot
> (the object even has the same memory address). Any idea what might
> be causing this behavior?
>
> Here are the statements and queries I'm using:
>
> sensor_alias = sensor \
> .join(device, device.c.item_id==sensor.c.item_id) \
> .join(clips_object,
> device.c.item_id==clips_object.c.clips_instance_name) \
> .select(use_labels=True).alias()
>
> eager_detection = clips_object \
> .join(event, event.c.event_id ==
> clips_object.c.clips_instance_name) \
> .join(detection, detection.c.event_id == event.c.event_id) \
> .join(sensor_alias,
> sensor_alias.c.sensor_item_id==detection.c.fk_sensor_id) \
> .outerjoin(aspect_detection, aspect_detection.c.event_id ==
> detection.c.event_id) \
> .outerjoin(rf_detection, rf_detection.c.event_id ==
> detection.c.event_id) \
> .select(use_labels=True)
>
> dets =
> session
> .query
> (Detection
> ).options
> (contains_eager('sensor')).from_statement(eager_detection).all()
>
If sensor_alias represents the rows used to load Sensor objects,
contains_eager should say: contains_eager('sensor',
alias=sensor_alias).
Im also not entirely sure why the from_statement is needed. Since you
are loading Detection which directly links to Sensor, there shouldn't
be any issue with eagerloading sensor. In any case, if you run the
trunk, you should be able to eagerload subclass collections, such as:
sess
.query
(Clip
).with_polymorphic(Detection).options(eagerload(Detection.sensor)).all()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
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
-~----------~----~----~----~------~----~------~--~---