On Apr 17, 2008, at 10:42 PM, kris wrote:

>
> I am building a tree structure of D1 and D2 nodes..
>
> I am progressively generating a query as before execution using
> subqueries.
>
> s = session.query(D1).filter (...)._values(D1.c.id).statement
> ...
>
> q = session.query (D2).select_from (s).filter (s.base_id ==
> D2.parent_id)
>

"s" is going to select columns for D1. "q" is going to select columns  
for D2.  So the above manuever doesnt make much sense as "s" will not  
supply the columns which D2 needs.  a "select_from()" call is intended  
to provide a selectable which provides the same table columns as a  
base query against D2 would use.  The mapper isnt going to guess that  
the given selectable sort of corresponds to a particular base table  
(and in this case it doesn't even do that exactly since D1's columns  
are involved).


> print q
> SELECT anon_1.base_id AS anon_1_base_id
> FROM
>      (SELECT base.id AS base_id
>        FROM base JOIN derived1 ON base.id = derived1.id
>        WHERE ....) AS anon_1,
>       base, derived2
> WHERE anon_1.base_id = derived2.parent_id ORDER BY anon_1.base_id
>
>
> This seems to generating extra join expression with 'base'  without
> the filtering

right, the Query has no idea what you're trying to do and adds in  
"derived2" to the FROM clause since it is just adding those columns  
into the columns clause (whose table then shows up in the FROM).

>
> Any help appreciated.

write out the exact SQL statement from which you'd like to select rows  
from, either D1 or D2 rows or both, and we'll go from there.



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