query error

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




['<>', '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.

Understood, thx for explaination :)