Column not in table (legacy database)


#1

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


#2

On 12 Feb 2009, at 00:21, Pete wrote:

class Employee < ActiveRecord::Base
has_one :job

has_one :job, :foreign_key => “shssn”, :dependent => :destroy

set_primary_key “emssan”
def self.table_name() “peis301” end
def name
“#{emfnam} #{emlnam}”
end
end

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?

You probably need to define the foreign key in the has_one
relationship too.

Best regards

Peter De Berdt