Kohana 2 ORM custom primary key generating an error-Collection of common programming errors

In my DB I have a jobs table, a details table, and an employers table.

jobs and details are in a one-to-one relationship, and employers and details are in a one-to-many relationship. Not all jobs have details, but all details have one employer.

I thought it would make sense to drop the id field from details, and use the job_id field as the primary key. The DB engine is InnoDB, so primary key joins ought to be lightning fast.

So after changing the table and adding the primary key declaration in the details model I can still access details via $job->detail. However, this line of code:

$employer = $job->detail->employer->name;

generates an error:

Undefined index: detail_job_id

I changed nothing aside from the custom primary key, so I know this is the source of the problem, but I’ve never used a custom primary key before, so I am not sure what is causing the error or what I need to fix.

Anyone used the Kohana2 ORM with custom primary keys?

  1. AFAIR, in v2.3.4 you can use $foreign_key property to define FK for related models. Something like protected $foreign_key = array('employer' => 'detail_id');

Originally posted 2013-11-27 12:09:04.