Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # it would be nice if we could do this:
- inception = Movie.find_by_title('Inception')
- alice = Moviegoer.find_by_username('alice')
- bob = Moviegoer.find_by_username('bob')
- # add reviews of Inception from figure
- alice_review_inception = Review.new(:potatoes => 5)
- bob_review_inception = Review.new(:potatoes => 3)
- # the one-to-many association from movies to reviews:
- inception.reviews = [alice_review_inception, bob_review_inception]
- inception.save!
- # and from moviegoers to reviews:
- alice.reviews = [alice_review_inception]
- alice.save!
- bob.reviews = [bob_review_inception]
- bob.save!
- # can we find out who wrote a review?
- bob_review_inception.moviegoer # => bob
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement