On Mar 30, 10:54 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> On Mar 30, 2010, at 2:47 AM, Kalium wrote:
>
>
>
> > Hi,
> > I've had a look through the docs and a quick look through the forum
> > here, and haven't been able to solve my problem. I'm using 0.4
>
> > The following works as expected.
>
> > q =
> > System.query().join('activity').group_by(model.System.id).add_column(func.max(Activity.id))
>
> > The add_column() recognises that the activity table is already joined.
> > and thus does not add it to the tables in the 'FROM' clause.
>
> > However, the following does not work. The only difference is that now
> > the joined table (activity) is aliased.
>
> > q =
> > System.query().join('activity',aliased=True).group_by(model.System.id).add_column(func.max(Activity.id))
>
> > add_column() does not recognise the aliased activity table and the
> > from clause now looks something like 'FROM system,activity', whereas
> > it should be joined.
>
> > What are my best solutions?
>
> in 0.4 you'd need to use SQL-level Table and alias() objects to achieve the 
> desired effect.  in 0.5 and above, you'd use aliased(Activity) as your 
> entity.    the "aliased=True" option only affects subsequent 
> filter/order_by/group_by calls.

Thanks Michael. Another reason to upgrade to 0.5

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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