Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 : Active Record add Not In condition

What is the active Record way of adding IN condition to an active Query in yii 1.x you could use CDbCriteria like this

$cr = new CDbCriteria(); $cr->addNotInCondition('attribute', $array); 

There seem to be no equivalent API call in yii2 active record implementation, how to do this via active record ?

like image 809
Manquer Avatar asked Sep 20 '14 18:09

Manquer


2 Answers

Well all query operands seems now merged within in yii\db\QueryInterface::Where() per documentation an In condition can now be added using something like

$query = MyModel::find()->where(['attribute'=>$array]); 

for a not In condition it is slightly different format

$query = MyModel::find()->where(['not in','attribute',$array]); 
like image 102
Manquer Avatar answered Sep 24 '22 15:09

Manquer


$query = MyModel::findAll(['not in ','attribute',$array]); 

http://www.yiiframework.com/doc-2.0/guide-db-active-record.html

like image 20
Oleg Ozimok Avatar answered Sep 25 '22 15:09

Oleg Ozimok