On May 1, 2009, at 2:55 PM, David Gardner wrote:

> Along those same lines, one of the things I would like to do is to  
> do an arbitrary join, my table is hierarchical and often I want to  
> do a join against a a node, along with another node two levels deep  
> below it, and since its a tree structure eager loading all of the  
> children, and grandchildren would be costly, when I only care about  
> two of them.
>
> So I have this:
>
> scn_alias=aliased(Asset)
> p='testshow/eps/201/s22/t04'
>
> take = session.query(Asset).filter(Asset.path==p).\
>         outerjoin((scn_alias,scn_alias.path=="%s/anim/ 
> scn"%p),aliased=True).one()
>
> This produces the correct SQL, but since scn_alias isn't directly  
> mapped as a relation to the row I am querying, I can't figure out  
> the correct arguments to pass to contains_eager().

contains_eager just needs to know what columns in the selectable it  
needs to draw from.   so again here, drop the aliased=True since  
scn_alias is already an alias, then pass scn_alias as the "alias"  
keyword to contains_eager().  Also your outerjoin should probably be  
qualified against the parent Asset object otherwise you're in danger  
of cartesian products.



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

Reply via email to