Okay so what I have is a table that keeps track of history on a "person", this logs the person(User), the handler(User), the status before(JobApplicationStatus), the status after(JobApplicationStatus).
Now in my head this translates down to a table of such:
**JobApplicationHistory** id (int) status_before_id (int) status_after_id (int) user_id (int) handler_id (int)
I tried to make a migation, that sorta worked, but it's not working right.
As I would like to use something like:
user = User.find(1) handler = User.find(1) status_before = JobApplicationStatus.find(1) status_after = JobApplicationStatus.find(2) history = JobApplicationHistory.new() history.user = user history.handler = handler history.status_before = status_before history.status_after = status_after history.save
Here is my migration
class CreateUserApplicationHistories < ActiveRecord::Migration
def self.up
create_table :user_application_histories do |t|
t.integer :user_id # goes to User
t.references :job # goes to Job
t.integer :handler_id # goes to User
t.integer :status_from_id # goes to JobApplicationStatus
t.integer :status_to_id # goes to JobApplicationStatus
t.timestamps
end
add_index("user_application_histories", "job_id")
add_index("user_application_histories", "handler_id")
add_index("user_application_histories", "user_id")
add_index("user_application_histories", "status_from_id")
add_index("user_application_histories", "status_to_id")
end
def self.down
drop_table :user_application_histories
end
end
And my model, which i think makes it fail
class UserApplicationHistory < ActiveRecord::Base
belongs_to :status_from_id, :class_name => "JobApplicationStatus"
belongs_to :status_to_id, :class_name => "JobApplicationStatus"
belongs_to :user_id, :class_name => "User"
belongs_to :handler_id, :class_name => "User"
end