Skip to content

Commit 99988ad

Browse files
committed
updateTemp: if temp has a clone, assign its new _id and reference in Model.copiesById
This makes it so that a clone does not have to be recloned (discarding potential user input changes) to obtain the new ID from the API server's create() response
1 parent 2303f26 commit 99988ad

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/service-module/service-module.mutations.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ export default function makeServiceMutations() {
145145
temp[state.idField] = id
146146
state.tempsByNewId[id] = temp
147147
}
148+
149+
// Add _id to temp's clone as well if it exists
150+
const Model = _get(models, `[${state.serverAlias}][${state.modelName}]`)
151+
const tempClone = Model && Model.copiesById && Model.copiesById[tempId]
152+
if (tempClone) {
153+
tempClone[state.idField] = id
154+
Model.copiesById[id] = tempClone
155+
}
148156
},
149157

150158
/**

0 commit comments

Comments
 (0)