whereAny
The whereAny method takes an array of condition objects. Each object in the array is OR'd together, and multiple keys within the same object are AND'd together:
await User.whereAny([{ email: null }, { name: null }]).all()
// [User{ email: null, name: 'chalupa joe' }, User{ email: 'how@yadoin', name: null }, ...]
This enables you to permit two adjacent conditions, essentially achieving the SQL equivalent of an OR clause. This is useful if you want an either-or case to apply.
Combining AND and OR
Because keys within one object are AND'd, and separate objects are OR'd, whereAny can express (A) OR (A AND B)-shaped conditions without a separate where:
// (givenName LIKE 'Anna%') OR (givenName LIKE 'Anna%' AND familyName LIKE 'Maria%')
query.whereAny([
{ givenName: ops.like('Anna%') },
{ givenName: ops.like('Anna%'), familyName: ops.like('Maria%') },
])
Difference from where
tip
Perhaps you want multiple where clauses, but you don't want them to be either-or. In this case, you are generally just looking for a regular where statement.