Based on your clarification, I think you basically have a many-to-many relationship between RecommendationSet
and Recommendation
. Presently, you have a one-to-many.
There are a couple of options:
- Use the
has_and_belongs_to_many
method in both models to describe the relationship; - Manually create a "join" model and then give both
RecommendationSet
andRecommendation
ahas_many
to this join model (with two correspondingbelongs_to
lines in the join model pointing to the other two models); - A
has_many ... :through
style, like you mentioned
Note that the first two options require you to have a join table.
If you require additional information on the join table/model, I tend to go with the 2nd option. Otherwise, either the first or third are perfectly valid.
Ryan Bates of RailsCasts made an episode about this here: http://railscasts.com/episodes/47-two-many-to-many
And some more information from the Rails documentation: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#label-Many-to-many
In short, if you don't need extra info on the join, I think your idea of the has_many ... :through
is perfectly fine.
Let me know whether that helps