Skip to content

Commit 101a7d3

Browse files
committed
fix getId to also check for props on the prototype
The `getId` check would fail if the `id` property was in somewhere in the prototype chain. This updates `getId` to also check the prototype properties.
1 parent c7af6fa commit 101a7d3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ export function getId(item, idField) {
184184
if (!item) {
185185
return
186186
}
187-
if (item.hasOwnProperty('id')) {
187+
if (item.id != null || item.hasOwnProperty('id')) {
188188
return item.id
189189
}
190-
if (item.hasOwnProperty('_id')) {
190+
if (item._id != null || item.hasOwnProperty('_id')) {
191191
return item._id
192192
}
193-
if (item.hasOwnProperty(idField)) {
193+
if (item[idField] != null || item.hasOwnProperty(idField)) {
194194
return item[idField]
195195
}
196196
}

0 commit comments

Comments
 (0)