On Dec 15, 2008, at 9:47 AM, Moshe C. wrote:
>
> Table T has a self referential parent_id column. 'parent' is an
> orm.relation using that column.
>
> I have the following code which obviously does not work
>
> myquery = T.query()
> myquery = myquery.outerjoin('parent', aliased=True)
> myquery = myquery.reset_joinpoint()
> myquery = myquery.order_by(func.if_(T.c.parent_id==None, T.c.name,
> T.c.name))
>
> With the 'reset_joinpoint' call, both T.c.name's in the last line will
> refer to the first
> instance of T. Without that call, both will refer to the joined
> instance (will use the alias).
>
> What I want is the first T.c.name in the if_() expression to refer to
> the first table instance, and the second T.c.name to refer to the
> joined table instance. I.e. the second T.c.name only should use the
> alias.
this is why in 0.5 we dont talk as much about the aliased=True flag,
since its a quick timesaver but is lacking for scenarios where you
need to get at both entities simultaneously. So instead use the
aliased() construct to build explicit class aliases - there's examples
in the tutorial. If you're on 0.4, use Table/Table.alias() objects
for this operation, the 0.4 tutorial should have some examples of
using query.select_from(table.join(somealias)).
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---