MOBILE-4640 db: Fix bug when updating primary key in memory database
Before this fix, the record was updated but the key was still the old primary key, so the new record wasn't found when using getOneByPrimaryKey.main
parent
9a1cd83207
commit
2abe483c6d
|
@ -172,7 +172,7 @@ export class CoreEagerDatabaseTable<
|
|||
continue;
|
||||
}
|
||||
|
||||
Object.assign(record, updates);
|
||||
this.updateMemoryRecord(record, updates, this.records);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ export class CoreEagerDatabaseTable<
|
|||
continue;
|
||||
}
|
||||
|
||||
Object.assign(record, updates);
|
||||
this.updateMemoryRecord(record, updates, this.records);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,4 +96,24 @@ export abstract class CoreInMemoryDatabaseTable<
|
|||
return rowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a record in memory.
|
||||
*
|
||||
* @param record Record to update.
|
||||
* @param updates New values.
|
||||
* @param records Records object.
|
||||
*/
|
||||
protected updateMemoryRecord(record: DBRecord, updates: Partial<DBRecord>, records: Record<string, DBRecord | null>): void {
|
||||
const previousPrimaryKey = this.serializePrimaryKey(this.getPrimaryKeyFromRecord(record));
|
||||
|
||||
Object.assign(record, updates);
|
||||
|
||||
const newPrimaryKey = this.serializePrimaryKey(this.getPrimaryKeyFromRecord(record));
|
||||
|
||||
if (newPrimaryKey !== previousPrimaryKey) {
|
||||
delete records[previousPrimaryKey];
|
||||
records[newPrimaryKey] = record;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ export class CoreLazyDatabaseTable<
|
|||
continue;
|
||||
}
|
||||
|
||||
Object.assign(record, updates);
|
||||
this.updateMemoryRecord(record, updates, this.records);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ export class CoreLazyDatabaseTable<
|
|||
continue;
|
||||
}
|
||||
|
||||
Object.assign(record, updates);
|
||||
this.updateMemoryRecord(record, updates, this.records);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue