On Jul 12, 2008, at 4:02 PM, Rick Morrison wrote:

>
> SA already has most of the join aliasing machinery to issue such a  
> query and do the in-memory join.  But......the problem is  
> restricting the set of 'children' to match those of 'vector' -- the  
> seemingly easiest thing would be to use a IN clause list of the  
> children's foreign key, like so:
>
>       WHERE children.foreign_key IN ([obj.primary_key for obj in  
> vector])

hibernate has a loading option somewhat like this, and the key is to  
re-use the original Query used to produce "vector" in order to load  
the child objects, using the same criterion except against a different  
set of table columns to be loaded.   the IN clause OTOH doesn't scale  
particularly well.  Hibernate implements the magic necessary around  
its collections to achieve this though I think its a complexity that  
few people ever use, or even are aware of.

>
> BTW it's kind of harder than it would seem to "roll your own" for  
> this one: If you take the naive approach to  just issue the query  
> for children with an eager load of grandchildren and do the in- 
> memory join in a loop:
>
>     keys = [item.id for item in vector]
>     all_children =  
> S 
> .query 
> (ChildObj 
> ).options 
> (eagerload('grandchildren')).filter(ChildObj.foreign_key.in_(keys))
>     dvec = dict((v.id, v) for v in vector)
>     for child in all_children:
>         dvec[child.foreign_key].children.append(child)
>
> you'll find you trigger an unwanted lazy-load by issuing the  
> children.append operation.

when you issue the original Query, you need to use the "noload()"  
option to disable loading on the target relations.   Unfortunately it  
seems we don't have test coverage for this little known option so I'm  
not sure how well its working atm, considering ticket 1105 which svil  
just posted.




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to