I am creating an application that allows you to send comments on 5 unique models (messages, photos, events, etc.), with 2 or 3 in transit. Basically, each model has an associated comment model (PostComments, PhotoComments, EventComments, etc.), although the comments themselves are usually the same for all models.
I recently discovered the power of polymorphic associations, beautifully explained in
Railscast # 154 , which would essentially combine many models into one model, and many tables into one table.
While polymorphic associations clear code and redundancy, how do they affect performance? I know little about database optimization, but it seems to take longer to request a comment of 1,000,000 lines in a common comment table than 200,000 lines in a specific comment table. Should I switch to polymorphic associations (while the application is still at a relatively early stage of development), or should I continue to create models / tables for each type of comment?
ruby-on-rails polymorphic-associations
aguynamedloren
source share