targetId property
int
targetId
Get ID of a relation target object.
Implementation
int get targetId {
if (_value._state == _ToOneState.unknown) {
// If the target was previously set while not attached, the ID is unknown.
// It's because we couldn't call _entity.getId() when _entity was null.
// If, in the meantime, we have become attached, the ID can be resolved.
if (_attached) {
target = _value._object;
} else {
// Otherwise, we still can't access the ID so let's throw...
_verifyAttached();
}
}
return _value._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);
}
}