Search code examples
ruby-on-rails-3squeel

Rails 3 - How to query on a polymorphic belongs_to association with squeel?


I am using acts_as_votable for my questions/answers application. Each question and each answer can be voted (à la stack overflow).

I am using squeel and looking for a way to get the following : order the questions from the most voted to the less voted ; and for each question, order the answers from the most voted to the less voted.

What should be the best squeel query for that ?


Solution

  • The best way to do this type of query is to use the cache system described in the main page of acts_as_votable and then perform this request : Question.order("cached_votes_up desc")