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 email1@somedomain.com')
    ->all();

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

$order = Order::find()
        ->isCompleted(true)
        ->email(['not', 'email1@somedomain.com', 'email2@otherdomain.com'])
        ->all();

Nor does passing in an array of addresses within the array

$order = Order::find()
        ->isCompleted(true)
        ->email(['not', ['email1@somedomain.com', 'email2@otherdomain.com']])
        ->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

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', ['nobody@example.com','no@example.com']])
    ->all();
  • Oh gosh that was a bit obvious! I'll give it a whirl, thank you. – foamcow Apr 8 '20 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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