target property
EntityT?
get
target
Returns the target object or null
if there is none.
ToOne uses lazy initialization, so on first access this will read the target object from the database.
Implementation
EntityT? get target {
if (_value._state == _ToOneState.lazy) {
final configuration = _getStoreConfigOrThrow();
var store =
StoreInternal.attachByConfiguration(configuration.storeConfiguration);
final EntityT? object;
try {
object = configuration.box(store).get(_value._id);
} finally {
store.close();
}
_value = (object == null)
? _ToOneValue<EntityT>.unresolvable(_value._id)
: _ToOneValue<EntityT>.stored(_value._id, object);
}
return _value._object;
}
set
target
(EntityT? object)
Prepares to set the target object of this relation.
Pass null
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 target(EntityT? object) {
// If not attached, yet, avoid throwing and set the ID to unknown instead.
// If the targetId getter is used later, it will call this to re-try
// resolving the ID.
if (object == null) {
_value = _ToOneValue<EntityT>.none();
} else if (_storeConfiguration != null) {
final id = _getId(object);
_value = (id == 0)
? _ToOneValue<EntityT>.unstored(object)
: _ToOneValue<EntityT>.stored(id, object);
} else {
_value = _ToOneValue.unknown(object);
}
}