Advertisement
saasbook

has_many_through_example.rb

Aug 15th, 2013
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.30 KB | None | 0 0
  1. # in moviegoer.rb:
  2. class Moviegoer
  3.   has_many :reviews
  4.   has_many :movies, :through => :reviews
  5.   # ...other moviegoer model code
  6. end
  7. alice = Moviegoer.find_by_name('Alice')
  8. alice_movies = alice.movies
  9. # MAY work, but a bad idea - see caption:
  10. alice.movies << Movie.find_by_name('Inception') # Don't do this!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement