I have two tables menusand lang_menus. My model is menusas follows:
public function relations()
{
return array(
'menulanguages'=>array(self::HAS_MANY, 'MenuLangs', 'menuId'),
);
}
...
public function getMenus(){
$criteria = new CDbCriteria();
$criteria->condition = "t.clientId = ".Yii::app()->user->clientId." AND menulanguages.languageId = ".Yii::app()->user->userlanguage;
$count = Menus::model()->with('menulanguages')->count($criteria);
$pages=new CPagination($count);
$pages->pageSize=10;
$pages->applyLimit($criteria);
$menus = Menus::model()->with('menulanguages')->findAll($criteria);
return array('menus' => $menus, 'paging' => $pages);
}
This causes an error Unknown column 'menulanguages.languageId'. The error is on the line $menus = Menus::model()->with('menulanguages')->findAll($criteria);.
Surprisingly, I correctly believe the value of a variable $count.
When looking at the log, I see that the SQL query that is executed for the findAll query is:
SELECT `t`.`id` AS `t0_c0`, `t`.`clientId` AS `t0_c1`, `t`.`restaurantId` AS `t0_c2` FROM `posif_menus` `t` WHERE (t.clientId = 1 AND menulanguages.languageId = 2) LIMIT 10
which means that the connection did not take place. If the correct connection request is made for the counter value. Am I doing something wrong? Please, help.
source
share