Given the relations
{
proposals(id, ...),
reviewers(id, ...),
comments(id, user_id, proposal_id, ...),
votes(id, user_id, proposal_id, ...)
}
how can I create an association from Vote to Comment? Each reviewer can vote once on a proposal "create unique index on votes(user_id, proposal_id)" and can comment many times. A reviewer can comment and not vote or vote and not comment so their is no dependency between votes and comments. From the vote model I wish to associate the many comments that match on (user_id, proposal_id). These are the comments that are relevant to a reviewers vote on a proposal.
The association
class Vote < ActiveRecord::Base
belongs_to :reviewer
belongs_to :proposal
has_many :comments, :through => :proposal
end
will yield comments from all reviewers. Likewise
has_many :comments, :through => :reviewer
will yield comments from all proposals. I'd like the intersection of the above two sets of comments.
Is it possible to
has_many :comments, :through => [:reviewer, :proposal]
or
has_many :comments, :through => :reviewer, :scope => :proposal_id
Neither of these work. What is the best way to work around this - or do I just need to read more documentation?