mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-25 19:27:24 +02:00
client: Allow updating existing works
This commit is contained in:
parent
adeb975890
commit
60989b2e18
1 changed files with 8 additions and 4 deletions
|
|
@ -256,16 +256,20 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
|||
await transaction(() async {
|
||||
final workId = workInfo.work.id;
|
||||
|
||||
// Delete old work data first. The parts, sections and instrumentations
|
||||
// will be deleted automatically due to their foreign key constraints.
|
||||
await deleteWork(workId);
|
||||
// Delete data associated rows in other tables first. We can't just
|
||||
// delete the work itself, because that would violate the foreign key
|
||||
// constraints.
|
||||
await (delete(instrumentations)..where((i) => i.work.equals(workId)))
|
||||
.go();
|
||||
await (delete(workParts)..where((p) => p.partOf.equals(workId))).go();
|
||||
await (delete(workSections)..where((s) => s.work.equals(workId))).go();
|
||||
|
||||
// This will also include the composers of the work's parts.
|
||||
for (final person in workInfo.composers) {
|
||||
await updatePerson(person);
|
||||
}
|
||||
|
||||
await into(works).insert(workInfo.work);
|
||||
await into(works).insert(workInfo.work, mode: InsertMode.insertOrReplace);
|
||||
|
||||
// At the moment, this will also update all provided instruments, even if
|
||||
// they were already there previously.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue