Skip to content

Commit 4015fa5

Browse files
committed
Convert object ids to strings
This makes sure that client-side object ids are converted to strings while leaving all other functionality unchanged. Fixes #543
1 parent ec65b49 commit 4015fa5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/utils.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ export function assignTempId(state, item) {
210210
return newId
211211
}
212212

213+
function stringifyIfObject(val): string | any {
214+
if (typeof val === 'object' && val != null) {
215+
return val.toString()
216+
}
217+
return val
218+
}
219+
213220
/**
214221
* Get the id from a record in this order:
215222
* 1. the `idField`
@@ -218,20 +225,19 @@ export function assignTempId(state, item) {
218225
* @param item
219226
* @param idField
220227
*/
221-
export function getId(item, idField) {
228+
export function getId(item, idField?) {
222229
if (!item) {
223230
return
224231
}
225232
if (item[idField] != null || item.hasOwnProperty(idField)) {
226-
return item[idField]
233+
return stringifyIfObject(item[idField])
227234
}
228235
if (item.id != null || item.hasOwnProperty('id')) {
229-
return item.id
236+
return stringifyIfObject(item.id)
230237
}
231238
if (item._id != null || item.hasOwnProperty('_id')) {
232-
return item._id
239+
return stringifyIfObject(item._id)
233240
}
234-
235241
}
236242

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

0 commit comments

Comments
 (0)