#Vote Model
belongs_to :voteable, :polymorphic => true
belongs_to :voter, :polymorphic => true
#votes table
Voteid: integer, vote: boolean, voteable_id: integer, voteable_type: string, voter_id: integer, voter_type: string, created_at: datetime, updated_at: datetime
#User
has_many :voteables, :foreign_key => :voter_id, :class_name => "Vote"
has_many :votes, :foreign_key => :voter_id
#Vote_Item model
acts_as_voteable
has_many :voters, :class_name => "Vote", :foreign_key => :voteable_id
假设有50位用户投票选出了VoteItem1,最好的方法是找出这些50位用户中的大多数投票者投票的其他投票人?
由于
答案 0 :(得分:0)
你对多数人的构成并不太具体。这样的事情应该返回由一组用户投票的项目,从最高到最低。您可以添加一个条件,其中vote_count大于多数。
Vote_Item.find(:all, :joins => :votes,
:select => "votes.*, count(votes) vote_count",
:conditions => {:votes => {:user => @users}},
:group => "vote_items.id", :order => "vote_count desc")