I have a model named Song
. I also have a model named Listen
. A Listen
belongs_to :song
, and a song :has_many listens
(can be listen to many times).
In my model I want to define a method self.top
which should return the top 5 songs listened to the most. How can I achieve that using the has_many
relation?
I'm using Rails 3.1.
Thanks!
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…