Model Relations
I’ ve got a bit complex situation and I cannot quite understand the behavior
I have the following models :
For table languages with pk language_id
class Languages extends CActiveRecord
{
..
public function relations()
{
return array();
}
..
}
For table contents_text with pk (and fk) content_id & language_id
class ContentsText extends CActiveRecord
{
..
public function relations()
{
return array(
'languages' => array(self::HAS_ONE, 'Languages', 'language_id'),
);
}
..
}
For table contents with pk content_id
class Contents extends CActiveRecord
{
..
public function relations()
{
return array(
...
'text' => array(self::HAS_ONE, 'ContentsText', 'content_id'),
);
}
..
public function fetch($parent_id, $code)
{
return $this->with(array(
'text'=>array(
'with'=>'languages',
'condition'=>'`code`=\'en\''
),
))->findAll('`parent_id`=\''.$parent_id.'\'');
}
}
When function fetch is executed I would expect somthing like :
[sql]…
FROM contents
LEFT OUTER JOIN `contents_text`
LEFT OUTER JOIN `languages`
ON `languages`.`language_id` = `contents_text`.`language_id`
ON `contents_text`.`content_id` = `contents`.`content_id`
…[/sql]
but I get
[sql]…
FROM contents
t
LEFT OUTER JOIN `contents_text` `text` ON (`text`.`content_id`=`t`.`content_id`)
LEFT OUTER JOIN `languages` `languages` ON (`languages`.`language_id`=`text`.`content_id`)
…[/sql]
What am I missing?
( Windows 7 Home Premiun, Apache 2.0.64, PHP 5.2.4, MySQL 5.1, Yii v1.1.8 )