-
-
Notifications
You must be signed in to change notification settings - Fork 683
Open
Description
Dexie.js/src/classes/table/table.ts
Line 558 in 761a933
| for (const keyPath of Object.keys(changes)) { |
bulkUpdate(
keysAndChanges: readonly { key: any; changes: UpdateSpec<any> }[]
): PromiseExtended<number> {
const coreTable = this.core;
const keys = keysAndChanges.map((entry) => entry.key);
const changeSpecs = keysAndChanges.map((entry) => entry.changes);
const offsetMap: number[] = [];
return this._trans('readwrite', (trans) => {
return coreTable.getMany({ trans, keys, cache: 'clone' }).then((objs) => {
const resultKeys: any[] = [];
const resultObjs: any[] = [];
keysAndChanges.forEach(({ key, changes }, idx) => {
const obj = objs[idx];
if (obj) {
for (const keyPath of Object.keys(changes)) {
const value = changes[keyPath];
if (keyPath === this.schema.primKey.keyPath) {
if (cmp(value, key) !== 0) {
throw new exceptions.Constraint(
`Cannot update primary key in bulkUpdate()`
);
}
} else {
setByKeyPath(obj, keyPath, value);
}
}
This is an edge case. Regardless it does permit keeping the original and creating a new record.
You could clone the db object, apply all changes then check if the primary key has changed
Similarly to
Dexie.js/src/classes/collection/collection.ts
Line 531 in 2a4d7b2
| } else if (!outbound && cmp(extractKey(origValue), extractKey(ctx.value)) !== 0) { |
if (!outbound && cmp(extractKey(origValue), extractKey(ctx.value)) !== 0) {
// Changed primary key of inbound
then throw.
Or allow bulkUpdate to change keys like Table.update / Collection.modify
Metadata
Metadata
Assignees
Labels
No labels