you'd probably want to use select_from() in conjunction with orm.outerjoin(). its the last example at http://www.sqlalchemy.org/docs/ormtutorial.html#querying-with-joins .
you also might be able to say query(Vote).outerjoin((Vote, subquery.c.max_id==Vote.id)).
not sure what the "lack of aliasing" error is, subquery() returns an Alias() object.
which two names/functions are you referring to ?
>
> Thanks,
>
> Daniel
>
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>
>
>>> I've managed to fix it using sqalchemy.orm.outerjoin in conjunction
>>> with query's select_from function. Out of interest, why is the naming
>>> scheme different for these 2 functions?
>>
>> which two names/functions are you referring to ?
>>
>
> outerjoin and select_from, one seems to be lower case, the other,
> lower case with underscores. Is this because one is a function and the
> other is a method?
we use lowercase with underscores for all names, but the underscores aren't applied to words that colloquially tend to be one word like "outerjoin".
>
> unfortunately this:
>
> query(Vote).outerjoin((Vote, subquery.c.max_id==Vote.id))
>
> generates invalid SQL and this:
>
> query(Vote).outerjoin((subquery, subquery.c.max_id==Vote.id))
>
> has the join backwards, as ordering counts. I was trying things like:
>
> subquery.outerjoin((Vote, subquery.c.max_id==Vote.id))
>
> This generates the rather indecipherable error "AttributeError:
> '_TextClause' object has no attribute 'foreign_keys'".
well in that last example subquery is not a Query() object, its an Alias construct. It has a different API and you should work through the SQL Expression Tutorial to get a feel for expression constructs. It probably shouldn't be making a text() construct out of a tuple, though. ticket 1847
> If you try
> doing the same query, but don't generate a subquery first the error is
> "Not unique table/alias: 'votes'".
>
> But as I say I found a workaround using the orm.outerjoin function, so
> this is rather academic from my perspective.
>
> Thanks,
>
> Daniel
>