1

When doing an order query I want to omit results for 2 particular email addresses.

It's easy enough to omit results for one address;

$order = Order::find()
    ->isCompleted(true)
    ->email('not [email protected]')
    ->all();

But how do I omit more than one email? If I pass an array using ['not', '[email protected]', '[email protected]'] then an error is returned stating that email expects a string. For example, this doesn't work

$order = Order::find()
        ->isCompleted(true)
        ->email(['not', '[email protected]', '[email protected]'])
        ->all();

Nor does passing in an array of addresses within the array

$order = Order::find()
        ->isCompleted(true)
        ->email(['not', ['[email protected]', '[email protected]']])
        ->all();

If I pass in 2 email criteria then only the latter is applied.

There has to be a neat way to do this.

1 Answer 1

1

Agree it'd be nice if it worked that way... I'm not sure why it doesn't, but replacing it with a regular where clause and not in works ok:

$order = Order::find()
    ->isCompleted(true)
    ->where(['not in', 'email', ['[email protected]','[email protected]']])
    ->all();
1
  • Oh gosh that was a bit obvious! I'll give it a whirl, thank you.
    – foamcow
    Apr 8, 2020 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.