Ren handleUndefined to normalizeUndefinedInQuery
This commit is contained in:
parent
89bb3079bd
commit
63f0fe20ed
20
lib/dao.js
20
lib/dao.js
|
@ -804,9 +804,9 @@ DataAccessObject.upsertWithWhere = function(where, data, options, cb) {
|
|||
function callConnector() {
|
||||
try {
|
||||
// Support an optional where object
|
||||
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
|
||||
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
|
||||
// alter configuration of how sanitizeQuery handles undefined values
|
||||
ctx.where = Model._sanitize(ctx.where, {handleUndefined: handleUndefined});
|
||||
ctx.where = Model._sanitize(ctx.where, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
|
||||
ctx.where = Model._coerce(ctx.where, options);
|
||||
update = Model._sanitize(update);
|
||||
update = Model._coerce(update, options);
|
||||
|
@ -1579,9 +1579,9 @@ DataAccessObject._normalize = function(filter, options) {
|
|||
Object.keys(this.definition.properties), this.settings.strict);
|
||||
}
|
||||
|
||||
var handleUndefined = this._getSetting('normalizeUndefinedInQuery');
|
||||
var normalizeUndefinedInQuery = this._getSetting('normalizeUndefinedInQuery');
|
||||
// alter configuration of how sanitizeQuery handles undefined values
|
||||
filter = this._sanitize(filter, {handleUndefined: handleUndefined});
|
||||
filter = this._sanitize(filter, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
|
||||
this._coerce(filter.where, options);
|
||||
return filter;
|
||||
};
|
||||
|
@ -2325,9 +2325,9 @@ DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
|
|||
} else {
|
||||
try {
|
||||
// Support an optional where object
|
||||
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
|
||||
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
|
||||
// alter configuration of how sanitizeQuery handles undefined values
|
||||
where = Model._sanitize(where, {handleUndefined: handleUndefined});
|
||||
where = Model._sanitize(where, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
|
||||
where = Model._coerce(where, options);
|
||||
} catch (err) {
|
||||
return process.nextTick(function() {
|
||||
|
@ -2480,9 +2480,9 @@ DataAccessObject.count = function(where, options, cb) {
|
|||
where = query.where;
|
||||
|
||||
try {
|
||||
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
|
||||
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
|
||||
// alter configuration of how sanitizeQuery handles undefined values
|
||||
where = Model._sanitize(where, {handleUndefined: handleUndefined});
|
||||
where = Model._sanitize(where, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
|
||||
where = this._coerce(where, options);
|
||||
} catch (err) {
|
||||
process.nextTick(function() {
|
||||
|
@ -2775,9 +2775,9 @@ DataAccessObject.updateAll = function(where, data, options, cb) {
|
|||
function doUpdate(where, data) {
|
||||
try {
|
||||
// Support an optional where object
|
||||
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
|
||||
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
|
||||
// alter configuration of how sanitizeQuery handles undefined values
|
||||
where = Model._sanitize(where, {handleUndefined: handleUndefined});
|
||||
where = Model._sanitize(where, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
|
||||
where = Model._coerce(where, options);
|
||||
data = Model._sanitize(data);
|
||||
data = Model._coerce(data, options);
|
||||
|
|
|
@ -306,7 +306,7 @@ function selectFields(fields) {
|
|||
* Sanitize the query object
|
||||
* @param query {object} The query object
|
||||
* @param options
|
||||
* @property handleUndefined {String} either "nullify", "throw" or "ignore" (default: "ignore")
|
||||
* @property normalizeUndefinedInQuery {String} either "nullify", "throw" or "ignore" (default: "ignore")
|
||||
* @property prohibitedKeys {String[]} An array of prohibited keys to be removed
|
||||
* @returns {*}
|
||||
*/
|
||||
|
@ -318,11 +318,11 @@ function sanitizeQuery(query, options) {
|
|||
options = options || {};
|
||||
if (typeof options === 'string') {
|
||||
// Keep it backward compatible
|
||||
options = {handleUndefined: options};
|
||||
options = {normalizeUndefinedInQuery: options};
|
||||
}
|
||||
const prohibitedKeys = options.prohibitedKeys;
|
||||
const offendingKeys = [];
|
||||
const handleUndefined = options.handleUndefined;
|
||||
const normalizeUndefinedInQuery = options.normalizeUndefinedInQuery;
|
||||
const maxDepth = options.maxDepth || 10;
|
||||
// WARNING: [rfeng] Use map() will cause mongodb to produce invalid BSON
|
||||
// as traverse doesn't transform the ObjectId correctly
|
||||
|
@ -351,7 +351,7 @@ function sanitizeQuery(query, options) {
|
|||
* Handle undefined values
|
||||
*/
|
||||
if (x === undefined) {
|
||||
switch (handleUndefined) {
|
||||
switch (normalizeUndefinedInQuery) {
|
||||
case 'nullify':
|
||||
this.update(null);
|
||||
break;
|
||||
|
|
|
@ -78,7 +78,7 @@ describe('util.sanitizeQuery', function() {
|
|||
should.deepEqual(sanitizeQuery(q5, 'nullify'), {where: {x: 1, y: null}});
|
||||
|
||||
q5 = {where: {x: 1, y: undefined}};
|
||||
should.deepEqual(sanitizeQuery(q5, {handleUndefined: 'nullify'}), {where: {x: 1, y: null}});
|
||||
should.deepEqual(sanitizeQuery(q5, {normalizeUndefinedInQuery: 'nullify'}), {where: {x: 1, y: null}});
|
||||
|
||||
var q6 = {where: {x: 1, y: undefined}};
|
||||
(function() { sanitizeQuery(q6, 'throw'); }).should.throw(/`undefined` in query/);
|
||||
|
|
Loading…
Reference in New Issue