From 9890af119e3194c52aca9e0372243b2486f33794 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Sat, 14 Dec 2013 09:54:28 -0800 Subject: [PATCH] Check for null & undefined values --- lib/dao.js | 3 +++ test/loopback-dl.test.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/dao.js b/lib/dao.js index d9394963..c5784212 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -407,6 +407,9 @@ DataAccessObject._coerce = function (where) { } var val = where[p]; + if(val === null || val === undefined) { + continue; + } // Check there is an operator var operator = null; if ('object' === typeof val) { diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index 488c7c86..bd24a623 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -654,6 +654,14 @@ describe('DataAccessObject', function () { assert.deepEqual(where, {location: {near: {lng: 10, lat: 20}, maxDistance: 20}}); }); + it('should skip null or undefined values', function () { + where = model._coerce({date: null}); + assert.deepEqual(where, {date: null}); + + where = model._coerce({date: undefined}); + assert.deepEqual(where, {date: undefined}); + }); + }); describe('Load models from json', function () {