whereReference method

void whereReference(
  1. String referenceUid,
  2. QueryReference reference
)
  • Reference Search Equals: Get entries having values based on referenced fields. This query retrieves all entries that satisfy the query conditions made on referenced fields.

  • Reference Search Not-equals: Get entries having values based on referenced fields. This query works the opposite of $in_query and retrieves all entries that does not satisfy query conditions made on referenced fields.

  • referenceUid is Reference field

  • reference It accepts Enum type QueryReference.include() OR QueryReference.NotInclude() and it accepts instance of Query Example:

final query = stack.contentType('room').entry().query();
query.referenceSearch('fieldUid', QueryReference.include(query: query));
await query.find().then((response){
   print(response);
});

Implementation

void whereReference(String referenceUid, QueryReference reference) {
  if (referenceUid != null && referenceUid.isNotEmpty) {
    reference.when(include: (queryInstance) {
      parameter[referenceUid] = {'\$in_query': queryInstance.query.parameter};
    }, notInclude: (queryInstance) {
      parameter[referenceUid] = {
        '\$nin_query': queryInstance.query.parameter
      };
    });
  }
}