trying to do
$criteria=new CDbCriteria(array(
'condition'=>'authorID=1',
'order'=>'id DESC',
'with'=>'author',
));
$dataProvider=new CActiveDataProvider('BlogPosts', array(
'pagination'=>array(
'pageSize'=> Yii::app()->params['postsPerPage'],
),
'criteria'=>$criteria,
));
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous. The SQL statement executed was: SELECT `t`.`id` AS `t0_c0`, `t`.`creationDate` AS `t0_c1`, `t`.`lastUpdate` AS `t0_c2`, `t`.`authorID` AS `t0_c3`, `t`.`comments` AS `t0_c4`, `t`.`title` AS `t0_c5`, `t`.`body` AS `t0_c6`, `t`.`tags` AS `t0_c7`, `author`.`id` AS `t1_c0`, `author`.`authKey` AS `t1_c1`, `author`.`registrationTime` AS `t1_c2`, `author`.`lastLoginTime` AS `t1_c3`, `author`.`ip` AS `t1_c4`, `author`.`userAgent` AS `t1_c5`, `author`.`username` AS `t1_c6`, `author`.`password` AS `t1_c7`, `author`.`email` AS `t1_c8`, `author`.`role` AS `t1_c9`, `author`.`ban` AS `t1_c10` FROM `tbl_blog_posts` `t` LEFT OUTER JOIN `tbl_users` `author` ON (`t`.`id`=`author`.`id`) WHERE (authorID=1) ORDER BY id DESC LIMIT 10
if i replace
id DESC to t.id DESC, it works… but what im doint wrong?
in user
public function relations()
{
return array(
'posts'=>array(self::HAS_MANY, 'BlogPosts', 'authorID'),
);
}
in blog posts
return array(
'author' => array(self::BELONGS_TO, 'User', 'id'),
);