Here's a seemingly simple ActiveRecord use case. I have Projects and
Users. Each project has a single team leader as well as a review team
that consists of several users. I would like to use the same User
model for authentication and just reference these users in my Project
model.
I tried this but got an "unknown column" error (for User.project_id)
class Project
has_one :lead, :class_name => 'User'
end
Any suggestions on how to model this relationship without requiring
references to Project in the User table?
From a database table viewpoint I would like
create_table :projects do |t|
t.integer :lead_id
t.timestamps
end
The review team part seems like it could be done with HBTM.
Here's a seemingly simple ActiveRecord use case. I have Projects and
Users. Each project has a single team leader as well as a review team
that consists of several users. I would like to use the same User
model for authentication and just reference these users in my Project
model.
I tried this but got an "unknown column" error (for User.project_id)
class Project
has_one :lead, :class_name => 'User'
end
Any suggestions on how to model this relationship without requiring
references to Project in the User table?
From a database table viewpoint I would like
create_table :projects do |t|
t.integer :lead_id
t.timestamps
end
The review team part seems like it could be done with HBTM.
Any thoughts?
Sean
You want belongs_to.
belongs_to :lead, :class_name => 'User'
And, because I forget of the foreign maps to the association name, or
the class name, you may need that to be: