Rails 4 - Many to many relationship -
i have bookmark
model. have list
model. users can create bookmark lists.
i've created list
scaffold command
rails generate scaffold list title:string
- a list can have many bookmarks
- a bookmark can have many lists
can me create list bookmark relationship.?
it awesome if can give me resources learn.
update:
- a bookmark can have many lists
lets bookmarked http://stackoverflow.com
. , have 2 lists like:
- programming help
- favorite sites
then should able add bookmark both lists.
so guess a bookmark can have many lists
valid statement.
applicable => rails 4:
app/model/bookmark.rb
class bookmark < activerecord::base has_and_belongs_to_many :lists end
app/model/list.rb
class list < activerecord::base has_and_belongs_to_many :bookmarks end
create new migration
rails generate migration createjointablelistbookmark list bookmark
migrate
rake db:migrate
Comments
Post a Comment