Guest User

Untitled

a guest
May 31st, 2018
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. ## Question:
  2. How can I get movie details like title using created relations? Should I correct them?
  3. ## Console
  4. ernest@ernest-desktop:~/Dokumenty/Projekty/bort$ script/console
  5. Loading development environment (Rails 2.2.2)
  6. >> user = User.find(1)
  7. => #<User id: 1, login: "admin", identity_url: nil, name: "", email: "ernest@bzdury.pl", crypted_password: "683489dbe6a1c66b7a84310223b5ca64f498e7f5", salt: "aebe39509659f8c15383fd9970348017a8dd8e41", remember_token: nil, activation_code: nil, state: "active", last_active: "2008-12-27 03:13:09", remember_token_expires_at: nil, activated_at: "2008-12-27 02:13:10", deleted_at: nil, created_at: "2008-12-27 02:13:10", updated_at: "2009-01-03 21:33:04">
  8. >> user.favorites
  9. => [#<Favorite id: 8, fav_id: 58, fav_type: "Movie", user_id: 1, created_at: "2009-01-09 05:40:23", updated_at: "2009-01-09 05:40:23">, #<Favorite id: 9, fav_id: 55, fav_type: "Movie", user_id: 1, created_at: "2009-01-09 09:57:42", updated_at: "2009-01-09 09:57:42">, #<Favorite id: 10, fav_id: 55, fav_type: "Movie", user_id: 1, created_at: "2009-01-09 09:58:42", updated_at: "2009-01-09 09:58:42">, #<Favorite id: 11, fav_id: 55, fav_type: "Movie", user_id: 1, created_at: "2009-01-09 09:59:15", updated_at: "2009-01-09 09:59:15">, #<Favorite id: 12, fav_id: 55, fav_type: "Movie", user_id: 1, created_at: "2009-01-09 10:01:39", updated_at: "2009-01-09 10:01:39">]
  10. >> user.favorites.movies
  11. NoMethodError: undefined method `movies' for #<Class:0xa516f08>
  12. from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1833:in `method_missing_without_paginate'
  13. from /home/ernest/Dokumenty/Projekty/bort/vendor/gems/mislav-will_paginate-2.3.6/lib/will_paginate/finder.rb:167:in `method_missing'
  14. from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_collection.rb:370:in `send'
  15. from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_collection.rb:370:in `method_missing_without_paginate'
  16. from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2003:in `with_scope'
  17. from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_proxy.rb:202:in `send'
  18. from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_proxy.rb:202:in `with_scope'
  19. from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_collection.rb:366:in `method_missing_without_paginate'
  20. from /home/ernest/Dokumenty/Projekty/bort/vendor/gems/mislav-will_paginate-2.3.6/lib/will_paginate/finder.rb:167:in `method_missing'
  21. from (irb):3
  22. >>
  23. ## Movie model
  24. has_many :favorites, :as => :fav
  25. ## User model
  26. has_many :favorites
  27. has_many :movies
  28. ## Favorites model
  29. belongs_to :favs, :polymorphic => true
  30. belongs_to :user
Add Comment
Please, Sign In to add comment