0

I have two models, user and accounts. A user can have zero or more accounts. I can fetch all the users (with and without accounts) with the below query.

I also want to filter the users based on the account name for which I'm using the _ilike operator in line 14.

However, this will also return users with no accounts. How can we avoid this? enter image description here

Is there a way skip the condition in the arguments?

user10179187
  • 99
  • 1
  • 1
  • 6

1 Answers1

0

{} evaluates to true if any object exists. so you can use the _and operator as

_and: [
    {
      accounts: { name: { _ilike: $accountName } }
    },
    {
      accounts: {}
    }
]