Strance
(Shahrulhadi)
March 27, 2016, 4:23am
1
Hi, this one result in an error.
$kakitanganAddAll = Kakitangan::find()->where([['<>', 'id', $model->id], 'supervise_by' => null])->all();
This one success.
$kakitanganAddAll = Kakitangan::find()->where(['supervise_by' => null])->andWhere(['<>','id', $model->id])->all();
Can anyone explain why the first one error?
Because in the documentation
Hash Format
Hash format is best used to specify multiple AND-concatenated sub-conditions each being a simple equality assertion. It is written as an array whose keys are column names and values the corresponding values that the columns should be. For example,
// …WHERE (status
= 10) AND (type
IS NULL) AND (id
IN (4, 8, 15))
$query->where([
'status' => 10,
'type' => null,
'id' => [4, 8, 15],
]);
softark
(Softark)
March 27, 2016, 1:16pm
2
['<>', 'id', $model->id]
This is in operator format which can’t be used in hash format.
You could write like this:
kakitanganAddAll = Kakitangan::find()
->where([
'and',
['<>', 'id', $model->id],
['supervise_by' => null]
])
->all();
The whole condition is in operator format in which the operator is ‘and’. The operands are 2 sub-conditions: one is in operator format and the other is in hash format.
Strance
(Shahrulhadi)
March 28, 2016, 1:25am
3
Understood, thx for explaination