Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## User class
- class User < ActiveRecord::Base
- has_many :assigned_product_backlogs, :class_name => 'ProductBacklogs', :foreign_key => 'assignee_id'
- has_many :reported_product_backlogs, :class_name => 'ProductBacklogs', :foreign_key => 'reported_id'
- ## ProductBacklog Class
- class ProductBacklog < ActiveRecord::Base
- belongs_to :assignee, :class_name => 'User'
- belongs_to :reporter, :class_name => 'User'
- end
- ## some console magic (find a productbacklog, and find associated assigned user) √
- >> p = ProductBacklog.find(1)
- => #<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">
- >> p.assignee
- => #<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>
- ## But going the other way, and finding the user 1, and trying to find all associated product backlogs the user is assigned to dies.
- >> u = User.find(1)
- => #<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>
- >> u.assigned_product_backlogs
- NameError: uninitialized constant User::ProductBacklogs
- from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:102:in `const_missing'
- from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2049:in `compute_type'
- from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
- from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2045:in `compute_type'
- from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:151:in `send'
- from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:151:in `klass'
- from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:182:in `quoted_table_name'
- from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/has_many_association.rb:96:in `construct_sql'
- from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_collection.rb:21:in `initialize'
- from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations.rb:1297:in `new'
- from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations.rb:1297:in `assigned_product_backlogs'
- from (irb):25
- >>
Add Comment
Please, Sign In to add comment