Query in YII 2 getting a different result from the Where clause

Asked

Viewed 49 times

0

I’m conducting a consultation, where it contains a clause Where where the flag Status is to be applied during implementation.

But the result always comes, ignoring my clause.

Veiculo::find()->select([Veiculo::tableName() . '.id', "CONCAT(descricao, ' - ', placa) AS text"])
            ->innerJoin(ModeloVeiculo::tableName(), ModeloVeiculo::tableName() . '.id = ' . Veiculo::tableName() . '.fk_modelo_veiculo')
            ->where(['<>',Veiculo::tableName() . '.status' ,  4]) 
            ->andWhere(['like', 'placa', $q])
            ->orWhere(['like', 'descricao', $q])->funcaoFilter()->asArray()->all();

->Where(['!=',Vehicle::tableName() . '.status' , 4]) // Flag to filter vehicles with different status of type 4

  • I imagine the code is PHP, but to avoid problems, would be good you [Edit] the post and add the language tag.

1 answer

1


Reorganize your Where.

  ->where(['like', 'placa', $q])
            ->orWhere(['like', 'descricao', $q])
            ->andWhere(['<>' ,Veiculo::tableName() .'.status' ,  4])->funcaoFilter()->asArray()->all();

There was an error at the time of checking. orWhere was overwriting its clause, causing the result of the query to check only the OR.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.