Relationships in Ruby on Rails: what is the proper model building method for a list? -


i'm trying figure out proper way setup model , database if have list under itineraries...

database table

`users` id  `itinerary` id user_id items 

model

class user < activerecord::base   has_many :itineraries end  class itinerary < activerecord::base   belongs_to :user end 

this basics, if want have users input multiple items within itinerary? should have separate model , table that? under itinerary database table instead of items, should item_id?

`itinerary` id user_id item_id    # change here 

and have separate items table:

database table

items id itinerary_id    # relationship id name 

model

class item < activerecord::base   belongs_to :user   belongs_to :itinerary end  class itinerary < activerecord::base   belongs_to :user   has_man :items end 

or if isn't correct way, how display list of items within itinerary database table?

thanks!

adding answer of puce, has_many relationship, need not have column item_id under itinerary table.

it enough if have itinerary_id in items table alone.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -