【发布时间】:2010-08-03 17:57:28
【问题描述】:
#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 位用户中的大多数投票的其他 VoteItem 是什么?
谢谢
【问题讨论】:
标签: ruby-on-rails associations polymorphic-associations