Skip to content

Fix bug with checking for `id` field

Compare
Choose a tag to compare
@marshallswain marshallswain released this 23 Oct 09:22
· 709 commits to master since this release

The getId utility function has been updated to check the prototype chain for the id property.

/**
 * Get the id from a record in this order:
 *   1. id
 *   2. _id
 *   3. the `idField`
 * @param item
 */
export function getId(item, idField) {
  if (!item) {
    return
  }
  if (item.id != null || item.hasOwnProperty('id')) {
    return item.id
  }
  if (item._id != null || item.hasOwnProperty('_id')) {
    return item._id
  }
  if (item[idField] != null || item.hasOwnProperty(idField)) {
    return item[idField]
  }
}