XF 2.1 The “IS” condition in the where function

NikitOS

Well-known member
Hello.

I need to execute a query with the “WHERE IS” condition, but in the where function I do not see this condition:
PHP:
        switch ($operator)
        {
            case '=':
            case '<>':
            case '!=':
            case '>':
            case '>=':
            case '<':
            case '<=':
            case 'LIKE':
            case 'NOT LIKE':
            case 'BETWEEN':
                break;

            default:
                throw new \InvalidArgumentException("Operator $operator is not valid");
        }

Extending the repository class, I used this code:
PHP:
$this->finder('MV\SBI:Bans')->where('type', 'IS', null)->fetch()->count();
Strange, but it worked and I didn't get any errors. But when I created a widget that also uses the “IS” condition, I got an error.
How do I create a query with the condition "IS"?
 
IS NULL is handled automatically if you don’t provide an operator and the value is null.

PHP:
$this->finder('MV\SBI:Bans')->where('type', null)->fetch()->count();
 
Really.

It seems you forgot to describe this “magic” in the documentation.

The where method can support up to three arguments. The first being the condition itself, e.g. the column you are querying. The second would ordinarily be the operator. The third is the value being searched for. If you supply only two arguments, as you have seen above, then it automatically implies the operator is =
Based on this, I expected the following output:
Code:
SELECT `mv_bans`.*
FROM `mv_bans`
WHERE (`mv_bans`.`RemoveType` = NULL)
Therefore, I did not even check this method.

PS And why did the IS condition work in the repository class, although this is not true?
 
Back
Top Bottom