hydrate<TModel extends CModel> method

List<TModel> hydrate<TModel extends CModel>(
  1. List<TModel> models
)

Replenish managedObjects with new data. Any one of the models with a null .primaryKey will not be inserted. This avoids unexpected null collisions.

For convenience, the return value is the argument models, not the complete set of managed TModels. If the managed models are desired instead, use get.

Implementation

List<TModel> hydrate<TModel extends CModel>(List<TModel> models) {
  if (!manages(TModel)) return models;
  managedObjects[TModel] ??= {};

  for (final instance in models) {
    if (instance.primaryKey != null) {
      managedObjects[TModel]![instance.primaryKey!] = instance;
    }
  }

  return models;
}