I should probably mention that I set lazy=False on the children
relation in that example before this behavior worked.

Stephen Emslie

On 8/31/07, stephen emslie <[EMAIL PROTECTED]> wrote:
> On 8/20/07, Michael Bayer <[EMAIL PROTECTED]> wrote:
> > 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 ?
>
> After quite a bit of head-scratching I think I've got the hang of
> this. Here's what I'm doing using the basic_tree.py example
> (http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/adjacencytree/basic_tree.py):
>
> my_eager_alias = mynodes.alias()
> query = sess.query(TreeNode).filter_by(parent_id=None).\
>
> .filter(my_eager_alias.c.node_name == 'node2')
> query = query.from_statement(select([mynodes, my_eager_alias],
> query._criterion)).\
>              .options(contains_eager('children', alias=my_eager_alias))
>
> then query.one().children gives back just what I wanted!:
>
> {u'node2': node2 (4,1, 139342252)}
>
> this is exactly what you suggested and it works perfectly, it just
> took me a while to realize how the join would behave around that
> alias. However, one thing still remains as I'd like to be able to
> repeat this behavior for more than one level of the tree. In other
> words, if node2 in turn has children subnode1 and subnode2 (as in the
> example) I want subnode 1 to be eagerloading on node2's children
> relation just as node2 is eagerloading on the root's.
>
> so far my only attempt was to filter on more than one alias, but
> contains_eager refers to the statement as a whole and so only only one
> relation can be set against one of the aliases so it doesn't seem
> possible to chain these together.
>
> > I think theres probably some relatively simple options we can be
> > adding to Query here to support what you're trying to do....such as
> > contains_eager('children', alias=myalias, add_columns=True) which
> > would automatically add the columns to the Query's SELECT statement
> > without needing to construct your from_statement() like we're doing
> > above.
>
> This would certainly neaten things up :)
>
> Stephen Emslie
>

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