relationCount method

Condition<Target> relationCount(
  1. int relationCount, {
  2. String? alias,
})

Creates a condition to match objects that have relationCount related objects pointing to them.

// match customers with two orders
box.query(Customer_.orders.relationCount(2));

The relation count may be 0 to match objects that do not have any related objects. It typically should be a low number.

This condition has some limitations:

  • only 1:N (ToMany using @Backlink) relations are supported,
  • the complexity is O(n * (relationCount + 1)) and cannot be improved via indexes,
  • the relation count cannot be changed with param() once the query is built.

Implementation

Condition<Target> relationCount(int relationCount, {String? alias}) =>
    _RelationCountCondition<Source, Target>(
        _relationPropertyId, relationCount, alias);