John Cooling
John Cooling

Reputation: 415

CActiveDataProvider Querying on join

I have a simple SQL query, which I need to convert to use in Yii 1.1.

SELECT * 
FROM User 
INNER JOIN Role ON Role.UserId = User.Id
WHERE Role.Name = 'admin'

How is this written into the CActiveDataProvider?

Upvotes: 1

Views: 59

Answers (1)

John Cooling
John Cooling

Reputation: 415

I have came up with an answer. Hopefully it helps someone in the future.

$dataProvider = new ActiveDataProvider('User', array
(
     'criteria' => array
      (
          'with' =>'roles',
          'join' => 'INNER JOIN Role r ON r.UserId = User.Id',
          'condition' => 'r.Name=:term',
          'params' => array(':term'=>'admin')
      )
));

Upvotes: 1

Related Questions