ToOne<EntityT> constructor

ToOne<EntityT>({
  1. EntityT? target,
  2. int? targetId,
})

Create a ToOne relationship.

Normally, you don't assign the target in the constructor but rather use the .target setter. The option to assign in the constructor is useful to initialize objects from an external source, e.g. from JSON.

Implementation

ToOne({EntityT? target, int? targetId}) {
  if (targetId != null) {
    if (target != null) {
      // May be a user error... and we can't check if (target.id == targetId).
      throw ArgumentError(
          'Provide at most one specification of a ToOne relation target: '
          'either [target] or [targetId] argument');
    }
    this.targetId = targetId;
  } else if (target != null) {
    this.target = target;
  }
}