Cdbcriteria Addnotincondition

hi

I’ve an query like following:




SELECT  `id` 

FROM  `product` 

WHERE 'id' NOT 

IN (

SELECT  'pid'

FROM  `order` 

WHERE

`date` >=  '2013-08-14 12:00:00'


    )



I want to use CActiveDataProvider to get data.

So using CdbCriteria is necessary.

I tried CdbCriteria -> addNotInCondition ($column , $value);

but I found that $value should be an Array() not an SELECT query.

How should I do to fit with SQL command above ?

Thank in advanced !

Hi,

you can write the query something look like this…




$criteria = new CDbCriteria;

$criteria->select = 'id';

$criteria->addCondition("id <> (SELECT  'pid' FROM  `order` AND date >='2013-08-14 12:00:0' )");

$resultSet    =    Product::model()->findAll($criteria);

return $resultSet;

then after you want to fetch the all records so you want to must be call a for-each loop


$data_arr=array();

foreach ($resultSet as $data){

         $data_arr[]=array(

             'id' => $data->id,

        )

}

and call this array on CArrayDataProvider


 $arrayDataProvider = new CArrayDataProvider($data_arr, array('id' => 'id',

            'pagination' => array('pageSize' => 5),

        ));

I hope what i am saying

Thank for your reply, Ankit Modi!

By using addCondition, I used like this:




     $criteria = new CDbCriteria;

     $criteria->addCondition("t.id not in (SELECT  pid FROM  `order`)");

     $dataProvider = new CActiveDataProvider('product', array(

				'criteria' => $criteria

				)

 

and it worked !

good post it helped me a lot. thanks