create method
FutureOr<void>
create(
- ProjectModel entity, {
- bool createOpLog = false,
- DataOperation dataOperation = DataOperation.create,
override
The create
method creates a new entity.
Implementation
@override
FutureOr<void> create(
ProjectModel entity, {
bool createOpLog = false,
DataOperation dataOperation = DataOperation.create,
}) async {
return retryLocalCallOperation(() async {
final projectCompanion = entity.companion;
final targets = entity.targets;
final addressCompanion = entity.address
?.copyWith(relatedClientReferenceId: entity.id)
.companion;
await sql.batch((batch) {
batch.insert(
sql.project,
projectCompanion,
mode: InsertMode.insertOrReplace,
);
if (addressCompanion != null) {
batch.insert(
sql.address,
addressCompanion,
mode: InsertMode.insertOrReplace,
);
}
if (targets != null) {
final targetsCompanions = targets.map((e) {
return e.copyWith(clientReferenceId: entity.id).companion;
}).toList();
batch.insertAll(
sql.target,
targetsCompanions,
mode: InsertMode.insertOrReplace,
);
}
});
await super.create(entity, createOpLog: createOpLog);
});
}