On Jul 4, 2011, at 3:25 PM, Michael Tils wrote:

> Here is my mapping, this time in german...

OK, sifting through lots of extraneous details as well as the lack of the 
actual table definitions, it seems like you're looking to join from 
Building->BuildingCondition->Lookup.    

I don't use aliased=True very often, but I think its usage pattern would allow 
this:

lc1 = aliased(LookupSubclassOne)
lc2 = aliased(LookupSubclassTwo)

query(Building).\
    join(Building.condition,aliased=True).\
    join(lc1, BuildingCondition.rating, from_joinpoint=True).\
    join(Building.condition, aliased=True).\
    join(lc2, BuildingCondition.care_level, from_joinpoint=True).\
    filter(...)

I don't talk about aliased=True often because it has a specific effect on 
subsequent modifications to the query, which are then reset on the next call to 
join(), and its a little confusing/hard to explain.   In this case, the second 
and fourth calls to join() add from_joinpoint=True so that it goes from the 
previous joinpoint.

For a full explicit approach, just alias everything:

bc1 = aliased(BuildingCondition)
bc2 = aliased(BuildingCondition)
lc1 = aliased(LookupSubclassOne)
lc2 = aliased(LookupSubclassTwo)

query(Building).\
    join(bc1, Building.condition).\
    join(lc1, bc1.rating).\
    join(bc2, Building.condition).\
    join(lc2, bc2.care_level).\
    filter(...)

note I'm using the 0.7 style of joins here where you can say join(target, 
onclause) without an embedded tuple.


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