ruby on rails - Comments system : Hstore with normal association VS simple attributes with polymorfic association -


i create small social network share photos , videos , events:

photos table attributes : title, description, name

videos table attributes : title , description , name, runtime

events table attributes : title, description, date_begining, date_end

as can see there duplication between tree tables, not important @ all.

so each model (photo, video, event) should have possibility add comments, i'm using postgresql , simple way use polymorfic association, think can use hstore , treat of them (photo, video, event) single model (for example share) contains common attributes , add properties column shares table :

shares ( title:string, description:string, name:string, properties:hstore) 

with that, think don't need polymorfic association , , can add simple relation between share , comment models :

class share < activerecord::base      has_many :comments end  class comment < activerecord::base      belongs_to :share end 

my question here best method (faster + performance) ? , if use hstore, there possibility find problems in future if change or migrate database management system ?

hstore better hash data provide great flexibilities on attributes.

for simple use case of comment fixed attributes(no more body, title, user, commentable?), don't think it's necessary.

setting association simple

class photo < activerecord::base    has_many comments, as: :commentable end  class video < activerecord::base    has_many comments, as: :commentable end  class comment < activerecord::base    belongs_to :commentable, polymorphic: true end 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -