On Apr 16, 2009, at 2:31 PM, dykang wrote:
> inside = table.alias('inside')
>
> outside = inside.join(table, table.c.foo < 2)
> s = outside.select(use_labels=True).alias('outside')
>
> j = table2.join(s, table2.c.bar == outside.c.inside_foo)
>
> s = j.select(use_labels=True)
> rows = session.query(Test2).add_entity(Test, alias=inside).add_entity
> (Test, alias=outside).from_statement(s).all()
when you create a selectable, the columns on that selectable (i.e. the
'.c.' namespace) are children of that selectable. so if you had two
selectables:
SELECT id, name FROM table
and
SELECT id, name FROM (select id, name FROM table)
both have "id" and "name" in their column list, but have a different
parent selectable. you could have instead said:
SELECT "something" AS id, name FROM (select id, name FROM table)
and its more apparent above how "id" means something different based
on which selectable it belongs to.
So above, you're joining "table2" to "s". the ON clause must be in
terms of "table2" and "s", not "outside", which is meaningless in that
context.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---