On Sep 27, 2011, at 1:16 PM, King Simon-NFHD78 wrote: > > Great, thanks a lot :-) I only discovered it in a toy application, and > the workaround (including order_by on the query) is not a problem. > > In this toy application, I was also wondering if there existed a > mechanism for doing some sort of "lazy subqueryload". ie. I'm loading a > collection of objects and I don't know ahead of time if I'm going to > access a particular relationship (so I don't want to eagerload it). > However, if I *do* access it, I'm going to access it on each object in > the collection, so I'd like to load all the related objects in a single > hit. It's just like a subqueryload, except it is only executed when the > relationship is accessed for the first time. > > Is that a silly idea? Or perhaps it already exists and I've missed it.
It actually exists in Hibernate, but not for us. We do sort of have the infrastructure in place to make it possible, i.e.the subqueryload right now prepares a Query object at query time that fires off during load time, with a mapper option it would need to stick it as some kind of memo in each InstanceState, it would be very tricky to implement. Keeping that state and keeping it plugged into the InstanceStates, then what if the loader was fired after many of the other states have been garbage collected, just a lot of corner cases to deal with. it can be handrolled of course, the general technique when you want to construct objects such that they appear "loaded" is to use attributes.set_commited_value() to set an attribute such that the ORM sees it as "what was loaded from the database". an example of that is where we first introduced the "subquery" concept here: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DisjointEagerLoading > > Thanks, > > Simon > > -- > 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 > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.