Re: [DataMapper] Performing subqueries on order by

43 views
Skip to first unread message

Ken Barber

unread,
Oct 9, 2012, 12:13:56 PM10/9/12
to datam...@googlegroups.com
> Is it at all possible to construct a query using Datamapper, that allows one
> to use subqueries passed to an order by?
>
> For example:
>
> select users.id from users order by (select count(*) from mods where
> mods.owner_id = users.id) asc;

So I converted the query into a left out join and fed it through
find_by_sql (dm-ar-finders) which at least gets me a collection which
is nice:

API::Models::User.find_by_sql(['select users.id from users left
outer join mods on mods.owner_id = users.id group by users.id order by
count(*)'])

But it still means resorting to SQL.

ken.
Reply all
Reply to author
Forward
0 new messages