BTW, aliased() and alias() don't work on a label() either. I tried
passing the label object straight into the order_by() as well to no
avail. I'm all out of ideas.

On Jan 9, 3:47 am, Yuen Ho Wong <wyue...@gmail.com> wrote:
> Hi,
>
> I have a rather complicated problem and I was wondering if you guys
> could help.
>
> So I have a query, session.query(Product, Merchant, d), where Product
> is 1-to-many with Merchant, and d is the distance from some lat long.
> d is actually a sqlalchemy.sql.label() of some complicated GeoAlchemy
> function calls.
>
> Product has a number of collections in which I would like to load
> using subqueryload_all() as well, and the result is ordered by
> "distance" as in order_by("distance"), where "distance" is the name of
> the label d.
>
> My problem is, since I'm supplying the Query object with an explicit
> order_by() name, when I use subqueryload(), the order_by() name is put
> into the subquery as is, because SQLAlchemy doesn't know any better
> with a plain string. If I pass in a column element, SQLAlchemy seems
> to know not to put an ORDER BY in the subquery. This seems to me like
> a bug because a subqueryload() always join on the primary key of the
> previous SELECT, so unless the name is the primary key name, it really
> shouldn't be put in the subquery.
>
> So finally my question, if this is too hard to fix, is there an option
> somewhere that I can tell SA to ignore the previous order_by() when
> doing a subqueryload()? If not, and I can't wait for a fix now, is
> there a way where I can turn my distance label into a ClauseElement so
> that SA knows not to put into the subquery when loading collections?
>
> Thanks in advance!

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