如何根据爱好者的数量列出索引页面中的所有游戏?感谢
class Game < ActiveRecord::Base
has_many :reverse_relationships, :dependent => :destroy, :foreign_key => "game_id", :class_name => "Relationship"
has_many :lovers, :through => :reverse_relationships, :source => :user_id
end
答案 0 :(得分:2)
尝试这样的事情:
Game.all(:include => :lovers).sort{|a,b| b.lovers.size <=> a.lovers.size}