unknownbits
unknownbits

Reputation: 2885

how to get data from inner join using cdbcriteria in yii?

This is my SQL. I want to create a CDbCriteria in Yii.

select us.user_id,u.clientid from user_session us
inner join user u on u.id=us.user_id
where us.auth_token='authtoken0000000001'

I tried this, but gives the wrong result. I also defined a relation related in my user_session model for this.

 $criteria = new CDbCriteria;
 $criteria->select = "user_id,user.clientid as client_id";
 $criteria->condition='auth_token="'.$token.'"';
 $clientIdarray = UserSession::model()->with('related')->find($criteria);

Upvotes: 0

Views: 5087

Answers (1)

ineersa
ineersa

Reputation: 3435

$dataprovider=New CActiveDataProvider('Bla',
    array(
    'criteria'=>array(      
      'order'=>'id ASC',
      'with'=>array(
        'user',
        ),
    'joinType'=>'INNER JOIN',               
    'condition'=>'user.auth_token = '.$token,
        )
        )); 

Just an example how to do dataprovider init. $criteria->with do what you need. This topic will help. http://www.yiiframework.com/doc/guide/1.1/en/database.arr

Upvotes: 1

Related Questions