I have two tables. applicants and applicant_accounts.
applicants
->applicant_id int(11) PK
->name varchar(45)
applicant_accounts
->account_id int(11) PK
->applicant_id int(11)
->userName varchar(45)
I've put this code code in my Applicants_Model it does'nt worked.
protected $has_one = array('applicant_account' => array('model' => 'Applicant_Account', 'foreign_key' => 'applicant_id'));
I tried to rename the primary keys into "id" and achieved my desired result by putting this code in my Applicants_Model.
protected $has_one = array('applicant_account');
And then accessed data from it by this
$applicant = ORM::factory('applicant', 1);
echo $applicant->name.' ----> '.$applicant->applicant_account->userName;
Please help me.I need to know how to have has_one relationship within two tables with primary keys not named as "id"
Applicant_Model
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Applicant_Model extends ORM {
protected $has_one = array('applicant_account' => array('model' => 'Applicant', 'foreign_key' => 'applicant_id'));
protected $primary_key = 'applicant_id';
}
Applicant_Account_Model
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Applicant_Account_Model extends ORM {
protected $primary_key = 'account_id';
}
testing.php(for displaying purposes only)
$applicants = ORM::factory('applicant', 1);
echo $applicant->name.' | '.$applicant->applicant_account->userName.'<br>';