Chaneg from CSqlDataProvider to CActiveDataProvider

Its my request for Cgridview.

I used CSqlDataProvider. I want know,it is possible to write this query using CActivDataProvider or just I must use CSqlDataProvider or CArrayDataProvider?


$sql = 'select *

from (

    select * from `table1` WHERE user_id != 1 LIMIT 10

    union 

    select * from `table1` WHERE user_id = 1

) a

left join table2 on a.user_id = table2.id';

Hi,

You could try the code below:




$connection=Yii::app()->db;


$sql = 'select *

from (

    select * from `table1` WHERE user_id != 1 LIMIT 10

    union 

    select * from `table1` WHERE user_id = 1

) a

left join table2 on a.user_id = table2.id';


$command=$connection->createCommand($sql);

$rawData=$command->query()->readAll();


$provider = new CArrayDataProvider($rawData);

I don’t think you can create a union query using CDbCriteria. CSqlDataProvider is probably your best bet