开发者

Kohana 2 ORM custom primary key generating an error

开发者 https://www.devze.com 2023-03-07 12:07 出处:网络
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 hav

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?


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');

0

精彩评论

暂无评论...
验证码 换一张
取 消