On Wednesday, March 26, 2014 2:08:32 PM UTC-7, Robert Sheldon wrote:
>
> hi there,
>  I have two models in my code:
>
> class User < Sequel::Model
> many_to_many :subscriptions
> end
>
> class Subscription < Sequel::Model
> many_to_many :users
> end
>
>
> and I want to be able to do something like
>
> Subscription.order(:users).limit(10)
>
> to get the most subscribed to subscriptions. Is there a way to do this via 
> model associations or should I just drop to the SQL abstraction?
>

So you are ordering based on the count of subscribers?  There's nothing 
built in for that.  You could drop down to SQL or do something like:

Subscription.order(DB[:subscriptions_users].where(:subscription_id=>:subscriptions__id).select{count(:*){}}.desc).limit(10)

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to