targetId property

int get targetId

Get ID of a relation target object.

Implementation

int get targetId {
  if (_value._state == _ToOneState.unknown) {
    // The target was set while this was not attached, so the target setter
    // set the ID as unknown.
    // If this is attached now, re-set the target so the target setter
    // resolves the ID. If still not attached, throw.
    _getStoreConfigOrThrow();
    target = _value._object;
  }
  return _value._id;
}
set targetId (int? id)

Set ID of a relation target object. Note: this does not store the change yet, use Box.put() on the containing (relation source) object.

Implementation

set targetId(int? id) {
  id ??= 0;
  if (id == 0) {
    _value = _ToOneValue<EntityT>.none();
  } else if (_value._state == _ToOneState.unstored &&
      id == _getId(_value._object as EntityT)) {
    // Optimization for targetId being set from box.put(sourceObject)
    // after entity.setId(object, newID) was already called on the new target.
    _value = _ToOneValue<EntityT>.stored(id, _value._object as EntityT);
  } else if (_value._state != _ToOneState.unknown && id == _value._id) {
    return;
  } else {
    _value = _ToOneValue<EntityT>.lazy(id);
  }
}