Hi!
I’m new to Yii and am struggling with a problem that I can’t seem to solve. I have made a small example database to illustrate the problem, it looks like this:
1649
[size=“4”]What I’m trying to do[/size]
I’m trying to list all comments where the user has null in its’ name-field and pass it to a CListView-widget.
[size=“4”]How I’m trying to do it[/size]
// comments-model relations
public function relations()
{
return array(
'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
);
}
// comments-controller function
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Comments', array(
'criteria'=>array(
'condition'=>'user.name IS NULL',
'order'=>'t.id DESC',
'with'=>array('user'),
),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
// comments/index-view function
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
[size="4"]What is going wrong[/size]
With MySQL it works just fine and I get a list of my comments with NULL-named users.
However, if I switch to PostgreSQL I get the following error message:
CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "."
LINE 1: ..."user" ON ("t"."user_id"="user"."id") WHERE (user.name IS N...
^.
The SQL statement executed was: SELECT COUNT(DISTINCT "t"."id") FROM "comments" "t" LEFT OUTER JOIN "users" "user" ON ("t"."user_id"="user"."id") WHERE (user.name IS NULL)
If anyone can make sense of this and point me in the right direction I would very much appreciate it!
[size="4"]My setup[/size]
Yii 1.1.7
PostgreSQL 8.4.8
MySQL 5.1.54
Apache 2.2.17