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)
Prepares to set the target of this relation to the object with the given id
.
Pass 0
to remove an existing one.
To apply changes, put the object with the ToOne. For important details, see the notes about relations of Box.put.
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);
}
}