Hello,
I’m creating an app that will collect and display user-submitted
comments for several different content types. They comment structure
will be the same for each type.
I see two ways of doing this:
- define belongs_to relationships with all the different content
types in my comment.rb model:
belongs_to :type_a
belongs_to :type_b
…
This would also require a number of foreign keys in my comment table:
type_a_id :integer,
type_b_id :integer,
…
- create a model for each comment application:
CommentTypeA
CommentTypeB
I suppose I am worried about dealing with multiple foreign keys in
approach 1), and I also like the idea of having each comment type
contained in its own class and table, for easier modification down the
road in (second approach). And maybe validation would be easier with
the second approach. But on the other hand, 2) is a lot of repetition
(which of course is so not DRY), and could prove to be risky for other
reasons.
Does anyone with some related experience have any advice?
Thanks very much.