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

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -