save method

Future<Model> save()

Implementation

Future<Model> save() async {
  if (_isLoadedFromDB) {
    assert(id != null, 'Id cannot be null when loaded from database');
    if (entityMeta.timestamps) updatedAt = DateTime.now().toUtc();
    await query.update(where: _whereId, values: to_db_data).execute();
    return this as Model;
  }

  final recordId = await query.insert<PkType>(to_db_data);
  return (this
    ..id = recordId
    .._isLoadedFromDB = true) as Model;
}