Trying to get a simple through relation to work:
Country (1:n) Address (1:n) Location
relations in Location:
public function relations() {
return array(
'address' => array(self::BELONGS_TO, 'Address', 'address_id'),
);
}
relations in Address:
public function relations() {
return array(
'country' => array(self::BELONGS_TO, 'Country', 'country_id'),
'locations' => array(self::HAS_MANY, 'Location', 'address_id'),
);
}
relations in Country:
public function relations() {
return array(
'addresses' => array(self::HAS_MANY, 'Address', 'country_id'),
'locations'=>array(self::HAS_MANY,'Location','country_id','through'=>'addresses'),
);
}
On lazy loading "Country.locations" following sql query is generated:
SELECT `locations`.`id` AS `t1_c0`, `locations`.`name` AS `t1_c1`, `locations`.`address_id` AS `t1_c2`, `locations`.`short_name` AS `t1_c3`, `locations`.`main_area_id` AS `t1_c4` FROM `location` `locations` LEFT OUTER JOIN `address` `addresses` ON (`addresses`.`country_id`=`locations`.`id`) WHERE (`addresses`.`country_id`=:ypl0). Bound with :ypl0='1'
The ON clause in the left outer join is wrong. Correct would be addresses
.id
=locations
.address_id
.
Is this through definition incorrect or not possible in my relation scenario?