On Jun 13, 4:23 pm, Cory Johns [EMAIL PROTECTED] wrote:
I find myself in a situation where I need certain (normally lazy-loaded)
properties of an ORM class to be eagerloaded for a particular query. I pass
withoptions=[eagerload('property')] in to session.query(), and everything
works fine. At least, it did until the query picked up a record that had
been previously returned by another query without eagerloading. Because the
record was already cached in the session, it didn't pick up on the eagerload
option.
What I'd like to know is, is there a way to force the eagerloading query to
apply its eagerloading behavior, even if the record is already cached in the
session?
im assuming you mean one of the lead instances in your selection did
not get its collection updated since it was already present (as
opposed to, one of the eagerly loaded child items didnt get its
attributes refreshed).
I normally answer this along the lines of use load() to load the
instance, which reloads all of its attributes, or expire()/refresh()
an already loaded instance. but you are trying to load a set of
instances here and theres no public hook to indicate load() behavior
for a whole list.
this is something easy enough to add in version 0.4 of query so i will
for now show you the non-public way you can accomplish this:
query= session.query(MyClass).options(..).filter_by(..)..etc..
result = query._select_statement(query.compile(),
populate_existing=True)
the effect that the above will have is to completely disregard any
attributes set on elements that are already in the session; they'll
all be overwritten...i.e. all column-based attributes, collections,
etc. all the way down for everything accessed. its like calling
refresh() on every instance.
if you need finer grained options than that, i.e.
options(overwrite_collection('foo')), that would take a lot more
tinkering under the hood.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---