Reputation: 6649
I have this query in yii2
return static::find()->where(['truck_status' => 1])
->all();
Now i would like to use a not condition that is
return static::find()->where(['truck_status' !=> 1]) //this fails
->all();
But it fails
How do i go about this
Upvotes: 1
Views: 1202
Reputation: 161
You can use like this :
return static::find()->where(['!=','truck_status','1'])->all();
Upvotes: 1
Reputation: 1756
You can use a condition in Operator Format.
return static::find()
->where(['not', ['truck_status' => 1]])
->all();
Basically here you have [$operator, $operand1, $operand2]
where the operator must be a string like 'between', 'like', etc.
The operands depend on the operator you are using, so you should check the documentation.
Upvotes: 1
Reputation: 133400
You coud use operator notation
return static::find()->where(['<>' , 'truck_status',1])
->all();
this could be useful http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html take a look at the where section
Upvotes: 1