Two models: Review and User.
Review has three relevant fields: user_id
, reviewable_type
, and reviewable_id
. So, the associations look something like this:
User has_many :reviews
User has_many :reviews, :as => :reviewable
Review belongs_to :user
Review belongs_to :reviewable
How can I find the right 'set' of review开发者_运维技巧s from the User model? @user.reviews
vs...?
As a general case, how do we set up two models so multiple associations between them stay separate, and so the parent model can access each set of children independently?
do you mean @user.reviews vs @user.reviewable ?
I am not that familiar with rails 3.0, but in rails 2.x you could do
User has_many :review_something1, :class_name => "Review", :where => ...
User has_many :review_something2, :class_name => "Review", :where => ...
精彩评论