MeV
MeV

Reputation: 3968

yii CDbCriteria select not working?

I need to edit the query of my CGridView

so in my model I'm changing the function search() as follow:

$criteria=new CDbCriteria;
$criteria->select = "links.title, links.url, groups.title as grouptitle";
$criteria->join = " join groups on links.id_group = groups.id_group";
$criteria->addCondition("links.id_user = '" . Yii::app()->user->getId() . "'");

return new CActiveDataProvider($this, array(
    'criteria'=>$criteria,
));

But from my view I get an error which shows me that the select is incorrect:

The SQL statement executed was: SELECT COUNT(*) FROM `links` `t` join groups on links.id_group = groups.id_group WHERE links.id_user = '1'

why so?

Upvotes: 1

Views: 648

Answers (1)

topher
topher

Reputation: 14860

The default table alias is t unless set explicitly. You can do this by:

$criteria->alias = 'links';

Upvotes: 2

Related Questions