Skip to content

Commit

Permalink
Merge pull request #1 from mika-s/master
Browse files Browse the repository at this point in the history
Change to Object.prototype.hasOwnProperty.call due to changes in node.js. Also check for null.
  • Loading branch information
jbutko authored Aug 8, 2017
2 parents 0832e05 + 35ba7fa commit a797fb9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ module.exports = function(schema) {
for (var attribute in updateData) {
let isProtectedKey = protectedKeys.indexOf(attribute) > -1;
let keyIsArray = Array.isArray(updateData[attribute]);
let isObjectWithKeys = typeof modelInstance[attribute] == 'object' && !keyIsArray && Object.keys(modelInstance[attribute]).length;
let isObjectWithKeys = modelInstance[attribute] !== null && typeof modelInstance[attribute] == 'object' && !keyIsArray && Object.keys(modelInstance[attribute]).length;

let keyIsUpdatable = updateData.hasOwnProperty(attribute) && attribute !== '_id' && !isProtectedKey && !isObjectWithKeys;
let isNestedKey = updateData.hasOwnProperty(attribute) && attribute !== '_id' && !isProtectedKey && isObjectWithKeys;
let keyIsUpdatable = Object.prototype.hasOwnProperty.call(updateData, attribute) && attribute !== '_id' && !isProtectedKey && !isObjectWithKeys;
let isNestedKey = Object.prototype.hasOwnProperty.call(updateData, attribute) && attribute !== '_id' && !isProtectedKey && isObjectWithKeys;

if (keyIsUpdatable)
modelInstance[attribute] = updateData[attribute];
Expand Down

0 comments on commit a797fb9

Please sign in to comment.