Skip to content

Commit 3bd8c2e

Browse files
Merge pull request #468 from J3m5/patch-9
fix(utils): GetId - Check idField first - Fix #463
2 parents 3719495 + 5565e27 commit 3bd8c2e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,26 @@ export function assignTempId(state, item) {
212212

213213
/**
214214
* Get the id from a record in this order:
215-
* 1. id
216-
* 2. _id
217-
* 3. the `idField`
215+
* 1. the `idField`
216+
* 2. id
217+
* 3. _id
218218
* @param item
219+
* @param idField
219220
*/
220221
export function getId(item, idField) {
221222
if (!item) {
222223
return
223224
}
225+
if (item[idField] != null || item.hasOwnProperty(idField)) {
226+
return item[idField]
227+
}
224228
if (item.id != null || item.hasOwnProperty('id')) {
225229
return item.id
226230
}
227231
if (item._id != null || item.hasOwnProperty('_id')) {
228232
return item._id
229233
}
230-
if (item[idField] != null || item.hasOwnProperty(idField)) {
231-
return item[idField]
232-
}
234+
233235
}
234236

235237
// Creates a Model class name from the last part of the servicePath

0 commit comments

Comments
 (0)