Kohana 3.1 orm. How to make this has_one relashionship? -
Kohana 3.1 orm. How to make this has_one relashionship? -
i have 2 models: address
, country
. now, every address has 1 country. address
model has:
protected $_has_one = array('country' => array( 'model' => 'country', 'foreign_key' => 'code', ));
i load address
object:
$addr = orm::factory('address', 1); $country = $addr->country->find();
but $country
contains first record instead of related record country
table. doing wrong here? if yes, what's right way?
edit: table country
has pk code
, no fk. table address
has pk id
, fk country_code
your has_one property should follows:
protected $_has_one = array('country' => array( 'model' => 'country', 'foreign_key' => 'country_code', ));
foreign key key in table of current model links primary key of related model.
kohana kohana-orm
Comments
Post a Comment