I have a Course model which has_many reviews. My Review model has a rating field. What I would like is a query to find the top rated courses. I want to do this in the SQL in order to avoid returning all the course objects and then trying to rank and sort them.
Share
You don’t describe how you define “top rated”. It could be that you want the courses with the highest individual ratings:
Or you might want the courses with the highest total ratings:
Then on each of these you can call
first(10)to get the top ten by whichever criteria you want.