Guest User

Untitled

a guest
Jun 14th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. ## User class
  2. class User < ActiveRecord::Base
  3. has_many :assigned_product_backlogs, :class_name => 'ProductBacklogs', :foreign_key => 'assignee_id'
  4. has_many :reported_product_backlogs, :class_name => 'ProductBacklogs', :foreign_key => 'reported_id'
  5.  
  6.  
  7. ## ProductBacklog Class
  8. class ProductBacklog < ActiveRecord::Base
  9. belongs_to :assignee, :class_name => 'User'
  10. belongs_to :reporter, :class_name => 'User'
  11. end
  12.  
  13.  
  14. ## some console magic (find a productbacklog, and find associated assigned user) √
  15. >> p = ProductBacklog.find(1)
  16. => #<ProductBacklog id: 1, title: "Add states to product backlog", description: "we need to add states to the product backlog list w...", technical_value: nil, business_value: nil, assignee_id: 1, reporter_id: 2, product_backlog_state: nil, created_at: "2009-04-02 11:12:53", updated_at: "2009-04-02 11:17:47">
  17. >> p.assignee
  18. => #<User id: 1, login: "mark", name: "", email: "mark@wot.com", crypted_password: "3gbe1900e6g4103fcc0770b3ga3a7127b61dfe85", salt: "0215390c23r3391232afb2c3372asdf0d48105", created_at: "2009-01-08 23:58:17", updated_at: "2009-01-08 23:58:17", remember_token: nil, remember_token_expires_at: nil>
  19.  
  20. ## But going the other way, and finding the user 1, and trying to find all associated product backlogs the user is assigned to dies.
  21. >> u = User.find(1)
  22. => #<User id: 1, login: "mark", name: "", email: "mark@aussiev8.com.au", crypted_password: "2ebe1900e6d3f03fcc0770be713a7127b61dfe85", salt: "0215390c53a4d3391232afb2c3372de5a0d48105", created_at: "2009-01-08 23:58:17", updated_at: "2009-01-08 23:58:17", remember_token: nil, remember_token_expires_at: nil>
  23. >> u.assigned_product_backlogs
  24. NameError: uninitialized constant User::ProductBacklogs
  25. from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:102:in `const_missing'
  26. from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2049:in `compute_type'
  27. from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
  28. from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2045:in `compute_type'
  29. from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:151:in `send'
  30. from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:151:in `klass'
  31. from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:182:in `quoted_table_name'
  32. from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/has_many_association.rb:96:in `construct_sql'
  33. from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_collection.rb:21:in `initialize'
  34. from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations.rb:1297:in `new'
  35. from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations.rb:1297:in `assigned_product_backlogs'
  36. from (irb):25
  37. >>
Add Comment
Please, Sign In to add comment