target property
EntityT?
target
Get target object. If it's the first access, this reads from DB.
Implementation
EntityT? get target {
if (_value._state == _ToOneState.lazy) {
_verifyAttached();
final object = _box.get(_value._id);
_value = (object == null)
? _ToOneValue<EntityT>.unresolvable(_value._id)
: _ToOneValue<EntityT>.stored(_value._id, object);
}
return _value._object;
}
void
target=(EntityT? object)
Set relation target object. Note: this does not store the change yet, use Box.put() on the containing (relation source) object.
Implementation
set target(EntityT? object) {
if (object == null) {
_value = _ToOneValue<EntityT>.none();
} else if (_attached) {
final id = _getId(object);
_value = (id == 0)
? _ToOneValue<EntityT>.unstored(object)
: _ToOneValue<EntityT>.stored(id, object);
} else {
_value = _ToOneValue.unknown(object);
}
}