I need some help on the following model design : User model (user.rb) class User < ActiveRecord::Base has_many :analyses, :dependent => :destroy Analysis model (analysis.rb) class Analysis < ActiveRecord::Base belongs_to :instructor, :class_name => "User", :foreign_key => :instructor_id belongs_to :member, :class_name => "User", :foreign_key => :member_id creating an analysis works Analysis.create(:instructor_id => 1, :member_id => 2, :status => "pending") I can get : Analysis.first.instructor Analysis.first.member BUT User.find(1).analyses raise an error : ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''analyses.user_id'' is there any way to handle this design ? thanks a lot for your help (btw I use the inflection plural analysis -> analyses) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I need some help on the following model design : User model (user.rb) class User < ActiveRecord::Base has_many :analyses, :dependent => :destroy Analysis model (analysis.rb) class Analysis < ActiveRecord::Base belongs_to :instructor, :class_name => "User", :foreign_key => :instructor_id belongs_to :member, :class_name => "User", :foreign_key => :member_id creating an analysis works Analysis.create(:instructor_id => 1, :member_id => 2, :status => "pending") I can get : Analysis.first.instructor Analysis.first.member BUT User.find(1).analyses raise an error : ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''analyses.user_id'' is there any way to handle this design ? thanks a lot for your help (btw I use the inflection plural analysis -> analyses) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
To make that work you might have to do this: class User < ActiveRecord::Base has_many :instructor_analyses, :foreign_key => :instructor_id, :dependent => destroy has_many :member_analyses, :foreign_key => :member_id, :dependent => destroy def analyses instructor_analyses + member_analyses end end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.