attach method

void attach(
  1. Store store
)

Initialize the relation field, attaching it to the store.

Box.put() calls this automatically. You only need to call this manually on new objects after you've set target and want to read targetId, which is a very unusual operation because you've just assigned the target so you should know it's ID.

Implementation

void attach(Store store) {
  if (_attached) {
    if (_store != store) {
      throw ArgumentError.value(
          store, 'store', 'Relation already attached to a different store');
    }
    return;
  }
  _attached = true;
  _store = store;
  _box = store.box<EntityT>();
  _entity = InternalStoreAccess.entityDef<EntityT>(_store);
}