On 27 July 2010 08:59, Mohammed Alenazi <vb4...@gmail.com> wrote:
> Hi
> I have two tables: users and tickets. A user has many tickets which is
> defined in the model. I want to order the users based on the number of
> tickets they have. What is the easiest way to do it in Rails without
> writing to many SQL statements.
>

Look at adding a "counter cache" column to your User model to store
the amount of tickets associated to them. Then you can just use that
column to sort by in a normal find.

http://rails.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to