I have been pushing my way through the issues regarding using legacy
database tables and I am making some progress but have run into a
couple of challenges.
The test application I am working with has an employee master file
that has a primary key called “emssan”. I have an employee job record
that has a primary key of “shssn”. There is one, and only one, job
record for each employee record. I needed to join to the employee
master file to get the name to display on the job record so I built
this relationship:
class Job < ActiveRecord::Base
set_primary_key “shssn”
def self.table_name() “psts301” end
belongs_to :employee, :foreign_key => “shssn”
end
class Employee < ActiveRecord::Base
has_one :job
set_primary_key “emssan”
def self.table_name() “peis301” end
def name
“#{emfnam} #{emlnam}”
end
end
When I display the index, I get a list of employees with names.
Great. When I take the option to show the record, I get a record
returned to view. However, if I take the option to create or edit, I
get an error
Request Failed (code 500, Internal Error)
The log shows the following:
Column EMPLOYEE_ID not in table PSTS301
The question is: Why is Rails looking for a key called EMPLOYEE_ID
when I set the primary key value to “emssan”? How do I fix this?
Thanks