> my_eager_alias = mynodes.alias('mynodes')
> query = query.filter(...wahtever criterion you're using...)
> query = query.from_statement(select([mynodes, my_eager_alias],
> query._criterion)).\
>        .options(contains_eager('children', alias=my_eager_alias))
>        .options(eagerload('children.children'))
>
> That will set the "children" attribute to eagerly load against your
> my_eager_alias criterion and also set "chilrdren.children" to eager
> load.

This sounds right, except that I dont necessarily need
"children.children" to be eager too. Sorry if my terminology is
incorrect, but I think what I'm trying to describe is chaining joins
together and filtering each one such that aliases/properties on the
resulting object eagerly return the filtered property rather than the
unfiltered join.

for example:
query = query.filter(...some criterion for the root node...)
query = query.join('children', aliased=True, from_joinpoint=True)
query.options(eagerload('children')).filter_by(foo=bar)
node = query.one()

node.children will return a parent that has a child where foo=bar. But
calling node.children wont just return the child (or children) with
foo=bar, but *all* of node's children.

The idea is to load just the portion of the tree that I need in a
single query. It sounds rather ambitious, but I think it would be a
faster option than the multiple-query version I have working now so
its worth investigating.

> I'd be curious though if you could play around a little with
> the approach I just suggested to see if its at all workable ?

Definitely. I dont actually understand it yet, but I'll report back on
what I find.


Thanks for the help

Stephen Emslie

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