Page class contains language depended data, PageLang stores common data. Here is structure:

Page relations:
<?php public function relations()
{
return array(
'page' => array(self::BELONGS_TO, 'Page', 'pageId'),
);
}
PageLang relations (autogenerated was ‘page’ => array(self::HAS_MANY, ‘Page’, ‘pageId’) but with additional lang parameter it becomes 1:1 relation):
<?php public function relations()
{
return array(
// 'page' => array(self::HAS_MANY, 'Page', 'pageId'),
'pages' => array(self::HAS_ONE, 'Page', 'pageId'),
);
}?>
I use it with CActiveDataProvider:
<?php $dataProvider=new CActiveDataProvider('PageLang', array('criteria' => array(
'with' => array('pages'),
'condition' => 'pages.lang = :lang',
'params' => array(':lang' => Yii::app()->language),
'order' => 'pages.title ASC',
)));?>
With ‘condition’ => ‘pages.lang = :lang’ it returns all existing pages for current language. What i miss here is some additional instruction on join clause. Yii generates query:
SELECT *
FROM `PageLang` `t`
LEFT OUTER JOIN `Page` `pages`
ON (`pages`.`pageId`=`t`.`id`)
WHERE (pages.lang = 'en')
ORDER BY pages.title ASC LIMIT 10;
But i want to move lang parameter to join like that:
SELECT *
FROM `PageLang` `t`
LEFT OUTER JOIN `Page` `pages`
ON (`pages`.`pageId`=`t`.`id` AND `pages`.`lang` = 'en')
ORDER BY pages.title ASC LIMIT 10;
Then in grid view i want add links to create new page if lang is null otherways it will point to update action.