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: 1) 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, ... 2) 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
r.g. wrote:> > Does anyone with some related experience have any advice? >Polymorphic relationships should work for you.. class Comment belongs_to :comentable, :polymorphic => true class TypeA has_many :comments, :as => :commentable schema.. commentable_type :string commentable_id :integer -- http://www.5valleys.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a lot! That seems to be working well On Aug 14, 3:35 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> r.g. wrote: > > > Does anyone with some related experience have any advice? > > Polymorphic relationships should work for you.. > > class Comment > belongs_to :comentable, :polymorphic => true > > class TypeA > has_many :comments, :as => :commentable > > schema.. > commentable_type :string > commentable_id :integer > > --http://www.5valleys.com/--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---