I’m working on rails application with postgres db.I have a table called merchant_review_votes where schema is
-------------------------------------------------- id | integer user_id | integer merchant_review_id | integer value | integer created_at | timestamp without time zone updated_at | timestamp without time zone --------------------------------------------------
I’m creating a another section(say products) which involve voting is it a good idea to create another schema similar to this or modify the code and use just one table.
If just one table how will the schema look?. What kinda problems i can face..
This sounds like a good case for a Polymorphic Association.
You can then call
@merchant.reviewsand@product.reviewsto get the reviews of merchants and products, respectively. And you can call@review.reviewableto get the object that was reviewed.The polymorphic association is based on a table structure like this:
The
reviewable_typecolumn holds the class name of the “reviewable” object and thereviewable_idholds it’s id. In a migration you can create these columns using: