whereNotExists method

Query<T> whereNotExists(
  1. Query subquery
)

Adds a WHERE NOT EXISTS subquery predicate.

This is the inverse of whereExists. It checks if the subquery returns NO results.

Example:

// Find users who have no comments
final users = await context.query<User>()
  .whereNotExists(
    _context.query<Comment>()
      .whereColumn('comments.userId', 'users.id')
  )
  .get();

Implementation

Query<T> whereNotExists(Query<dynamic> subquery) {
  return _appendPredicate(
    SubqueryPredicate(
      type: SubqueryType.exists,
      subquery: subquery._buildPlan(),
      negate: true,
    ),
    PredicateLogicalOperator.and,
  );
}