attach method

void attach(
  1. Store store
)

Initializes this relation, attaching it to the store.

Calling this is typically not necessary as e.g. for objects obtained via Box.get or put with Box.put this is called automatically.

However, when creating a new instance of ToOne and setting target, this must be called before accessing targetId. But in that case it is likely easier to get the target ID from the target object directly.

Implementation

void attach(Store store) {
  final configuration = _storeConfiguration;
  if (configuration != null) {
    if (configuration.storeConfiguration.id != store.configuration().id) {
      throw ArgumentError.value(
          store, 'store', 'Relation already attached to a different store');
    }
    return;
  }
  _storeConfiguration = _ToOneStoreConfiguration(
      store.configuration(), InternalStoreAccess.entityDef<EntityT>(store));
}