required method

Selection<R> required({
  1. ToOneStrategy strategy = ToOneStrategy.automatic,
})

Requires one visible row while preserving the selected value's nullability.

Throws RELATION.MISSING for an absent row and RELATION.CARDINALITY for multiple selected rows. This validates row presence during decoding; it does not turn the parent query into an inner join.

Implementation

Selection<R> required({ToOneStrategy strategy = ToOneStrategy.automatic}) =>
    _useJoin(strategy)
    ? _JoinedRelationSelection<R, F>(this, required: true)
    : _oneBatch().map((rows) {
        if (rows.isEmpty) {
          throw const OrmException(
            'RELATION.MISSING',
            'A required related row is not visible.',
          );
        }
        return rows.single;
      });