put method

int put(
  1. T object, {
  2. PutMode mode = PutMode.put,
})

Puts the given object and returns its (new) ID.

If the object is new (its Id property is 0 or null), it is inserted and assigned a new ID. The new ID is set on the object. This also applies to new objects in its relations.

If an object with the same ID is already in the box, it will be updated. Otherwise the put will fail. This does not apply to existing objects in its relations, in this case only the relation is updated to point to the new target object(s).

Change mode to specify explicitly that only an insert or update should occur.

See putMany to put several objects at once with better performance.

See putAsync for an asynchronous version.

Implementation

int put(T object, {PutMode mode = PutMode.put}) {
  if (_hasRelations) {
    return InternalStoreAccess.runInTransaction(
        _store, TxMode.write, (Transaction tx) => _put(object, mode, tx));
  } else {
    return _put(object, mode, null);
  }
}