Error record.hasOwnProperty is not a function
Created by: eduardomourar
In massivejs v4.7.1, I am getting this error when criteria parameter passed does have function hasOwnProperty()
:
TypeError: record.hasOwnProperty is not a function
at criteria.pk.reduce (data-service\node_modules\massive\lib\table.js:47:16)
at Array.reduce (<anonymous>)
at Table.getPkCriteria (data-service\node_modules\massive\lib\table.js:46:28)
at Table.saveDoc (data-service\node_modules\massive\lib\table.js:177:25)
at DataTable.save (data-service\data-table.js:79:39)
at DataService.save (data-service\index.js:144:40)
at UserDirectory.save (iam-service\user-directory.js:68:36)
at <anonymous>
I have created on my repo branch this test that fails:
it('passing object without hasOwnProperty method', function () {
const criteria = Object.create(null);
criteria.title = 'Document 1';
return db.docs.findDoc(criteria).then(docs => {
assert.lengthOf(docs, 1);
assert.equal(docs[0].id, 1);
assert.equal(docs[0].title, 'Document 1');
assert.equal(docs[0].description, 'lorem ipsum etc');
});
});
One possible solution is to replace every time hasOwnProperty is used with Object.prototype.hasOwnProperty.call(obj, property)
.
I will submit a PR with code and test if that makes sense.