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()
---------------
The query SQLAlchemy prints with echo set to True returns the values
and fields I would expect, so I'm not sure what I'm doing wrong here.
Thanks for all the help thus far,
Chris
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---