Sampath Kanth
Sampath Kanth

Reputation: 11

Add key value pair columns to an existing model and database in rails

My Project have 2 models Users and posts. The relationship between them is user has_many posts and post belongs_to :users.

The model "Posts" that has a table with post_id, text of the post, and ref of another model User ie user_id. Now I need to add a columns of "keys" and "values" to the table of MODEL Posts. So I want to create a new table with the fields of post_id , user_id , key and value. For this do I need to create a new model ? or can I add a table to the existing model ? Any other suggestions ?

Upvotes: 0

Views: 333

Answers (1)

adamliesko
adamliesko

Reputation: 1915

You are looking for has_and_belongs_to_many option. With use of it, you do not have to create new model.

http://guides.rubyonrails.org/association_basics.html#the-has-and-belongs-to-many-association

Upvotes: 0

Related Questions