On May 26, 2011, at 5:03 PM, Israel Ben Guilherme Fonseca wrote:

> I saw that, but I'm not using a subquery in the from clause. Maybe I wasn't 
> clear enough. Example:
> 
> outeruser = aliased(User)
> inneruser = aliased(User)
> 
> innerselect = session.query(inneruser.id).filter(inneruser.id == 
> outeruser.id).subquery()
> 
> At this point I already have a problem, the generated from clause is 
> something like:
> 
> from user as user_2, user as user_1
> 
> I didnt want the other user_2, because the filter statement is actually 
> referencing the user of the outerselect:
> 
> outerselect = session.query(outeruser).filter(outeruser.id == innerselect)
> 
> I expected that the innerselect referenced the id of the outer select.

oh then you're looking for correlation:

        innerselect = session.query(inneruser.id).filter(inneruser.id == 
outeruser.id).correlate(outeruser) 

        outerselect = session.query(outeruser).filter(outeruser.id == 
innerselect.as_scalar())

for some reason the Query is disabling auto-correlation upon subquery(), 
.statement or as_scalar().   Sort of wish I had noticed that before releasing 
0.7.   Will add a ticket to possibly change that default for 0.8, see you in a 
year.


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

Reply via email to