I'm trying to figure out what is the proper way to setup my model and database if I have a 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 is the basics, but what if I want to have users to input multiple items within their itinerary? Should I have a separate model and table for that? so under itinerary
Database Table instead of items
, it should be item_id
?
`itinerary`
id
user_id
item_id # the change here
And have a 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 this isn't the correct way, how do you display a list of items within the itinerary database table?
Thanks!