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
class Job < ActiveRecord::Base
def self.table_name() “psts301” end
belongs_to :employee, :foreign_key => “shssn”
class Employee < ActiveRecord::Base
def self.table_name() “peis301” 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?