【发布时间】:2011-06-20 19:44:30
【问题描述】:
目前我有两个模型:Rate 和 Item
Rate是一种投票模式,有votes和player_id
率 has_many :votes 投票属于_to :rate
另外,对于 Item 模型,目前我的范围如下:
scope :pop, proc { order('votes.votes DESC') }
按投票对所有项目进行排序。
问题是:我需要收集按 player_id 排序的 (Item.all.pop) AND 项目 类似于:Item.all.pop(player_id)
怎么做?
更新:
rate.rb
class Rate < ActiveRecord::Base
belongs_to :player
belongs_to :item
end
item.rb
class Item < ActiveRecord::Base
has_many :rates
scope :pop, proc { order('rates.votes DESC') }
end
【问题讨论】:
标签: mysql ruby-on-rails named-scope