When looking at comments which will be made on different types (say
post, picture, article) I see a lot of advice towards using polymorphic
associations for this. Ryan Bates has a good railscast on it:

http://railscasts.com/episodes/154-polymorphic-association-revised

However, I'm not sure I see why this is such a good idea in this case.
Would it not make more sense to have multiple comment types:

PostComment < Comment
PictureComment < Comment

etc.

Now we have the same amount of comment rows and we maintain referential
integrity, although we do now have more tables..

Can someone point me in the direction of why polymorphic associations
are the way to go rather than using inheritance and multiple tables in
the db? Does it make much difference?

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f98bb2307ce8ccab226c17b74a9be722%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Greg Navis at May 24, 2016 at 11:06 am
    I think it depends on your use case. Things to consider:

    1. Selecting all comments of a user via 1 association or N associations
    (and 1 vs N queries).
    2. Storing more data in the table (:commentable_type).
    3. Maintaining and testing one model vs testing N models.

    I think the biggest problem with separate comment models is that references
    from other models are the fact that you need N times more associations to
    reference a comment (e.g. user.post_comments, user.picture_comments, ...
    instead of user.comments).

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAA6WWt-7%3DrrEpcs%2B84m9EiDCZa-XDKDAfAKrnuMvCKxkfCgUjg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMay 16, '16 at 12:51p
activeMay 24, '16 at 11:06a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Greg Navis: 1 post Johnny Stewart: 1 post

People

Translate

site design / logo © 2022 Grokbase