I have 3 table, that i want to fetch using single model -person model- :
table_person :
- index (pk)
- name
- address
- city_code
- country_code
table_city :
- index (pk)
- city_code
- city_name
table_country :
- index (pk)
- country_code
- country_name
like you see i not put any constrain all table. In "table_person" model i put this relation without defining PK on relation because its using diffrent PK than index in table :
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'city'=>array(self::HAS_ONE,'table_city','[intentionaly empty]','on'=>'city_code=city.city_code'),
'country'=>array(self::HAS_ONE,'table_country','[intentionaly empty]','on'=>'country_code=country.country_code'),
);
}
i expected when i pass person to variable $PERSON. And call value
$PERSON->city->city_name
or
$PERSON->country->country_name
should return "city_name" or "country_name" with matching city_code or country_code, but it not return like it.
Instead it always return first row from "city_table" or "country_table".
I have change self::HAS_ONE to self::BELONGS_TO and 'on'=>'city_code=city.city_code' to 'condition'=>'city_code=city.city_code', but with no avail.
Can someone help me fix it?
Thank You.

Help













