ActiveRecord model design help

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)

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs