diff --git a/lib/waterline/utils/query/forge-stage-two-query.js b/lib/waterline/utils/query/forge-stage-two-query.js index ab14685ed..a03968e90 100644 --- a/lib/waterline/utils/query/forge-stage-two-query.js +++ b/lib/waterline/utils/query/forge-stage-two-query.js @@ -580,7 +580,7 @@ module.exports = function forgeStageTwoQuery(query, orm) { // └─ ┴└ ┴ ┴ ┴┴└─┘ ┴└─┘ ┴ ┴ ╚ ╩╝╚╝═╩╝ ╚═╝╝╚╝╚═╝ └─┘└└─┘└─┘┴└─ ┴ ─┘ // If this is a `findOne` query, then if `where` clause is not defined, or if it is `{}`, // then fail with a usage error for clarity. - if (query.method === 'findOne' && Object.keys(query.criteria.where).length === 0) { + if (query.method === 'findOne' && _.isEqual(query.criteria.where, {})) { throw buildUsageError('E_INVALID_CRITERIA', 'Cannot `findOne()` without specifying a more specific `where` clause. (If you want to work around this, use `.find().limit(1)`.)', query.using); diff --git a/lib/waterline/utils/query/private/normalize-criteria.js b/lib/waterline/utils/query/private/normalize-criteria.js index 7b2afdf22..dade6d5fa 100644 --- a/lib/waterline/utils/query/private/normalize-criteria.js +++ b/lib/waterline/utils/query/private/normalize-criteria.js @@ -65,6 +65,10 @@ var NAMES_OF_RECOGNIZED_CLAUSES = ['where', 'limit', 'skip', 'sort', 'select', ' * The Waterline ORM instance. * > Useful for accessing the model definitions. * + * @param {Dictionary?} meta + * The contents of the `meta` query key, if one was provided. + * > Useful for propagating query options to low-level functions like this one. + * * -- * * @returns {Dictionary} @@ -85,7 +89,7 @@ var NAMES_OF_RECOGNIZED_CLAUSES = ['where', 'limit', 'skip', 'sort', 'select', ' * * @throws {Error} If anything else unexpected occurs. */ -module.exports = function normalizeCriteria(criteria, modelIdentity, orm) { +module.exports = function normalizeCriteria(criteria, modelIdentity, orm, meta) { // Sanity checks. // > These are just some basic, initial usage assertions to help catch diff --git a/lib/waterline/utils/query/private/normalize-where-clause.js b/lib/waterline/utils/query/private/normalize-where-clause.js index 3328bc508..6a61ac4ec 100644 --- a/lib/waterline/utils/query/private/normalize-where-clause.js +++ b/lib/waterline/utils/query/private/normalize-where-clause.js @@ -397,17 +397,17 @@ module.exports = function normalizeWhereClause(whereClause, modelIdentity, orm) var soleBranchKey = _.keys(branch)[0]; - // ┬ ┬┌─┐┌┐┌┌┬┐┬ ┌─┐ ╔═╗╦╦ ╔╦╗╔═╗╦═╗ - // ├─┤├─┤│││ │││ ├┤ ╠╣ ║║ ║ ║╣ ╠╦╝ - // ┴ ┴┴ ┴┘└┘─┴┘┴─┘└─┘ ╚ ╩╩═╝╩ ╚═╝╩╚═ + // ┬ ┬┌─┐┌┐┌┌┬┐┬ ┌─┐ ╔═╗╔═╗╔╗╔╔═╗╔╦╗╦═╗╔═╗╦╔╗╔╔╦╗ + // ├─┤├─┤│││ │││ ├┤ ║ ║ ║║║║╚═╗ ║ ╠╦╝╠═╣║║║║ ║ + // ┴ ┴┴ ┴┘└┘─┴┘┴─┘└─┘ ╚═╝╚═╝╝╚╝╚═╝ ╩ ╩╚═╩ ╩╩╝╚╝ ╩ // If this key is NOT a predicate (`and`/`or`)... if (!_.contains(PREDICATE_OPERATOR_KINDS, soleBranchKey)) { // ...then we know we're dealing with a constraint. - // ╔═╗╦═╗╔═╗╔═╗╔╦╗╦ ╦╦═╗╔═╗ ┌─┐┌─┐┌┬┐┌─┐┬ ┌─┐─┐ ┬ ┌─┐┬┬ ┌┬┐┌─┐┬─┐ - // ╠╣ ╠╦╝╠═╣║ ║ ║ ║╠╦╝║╣ │ │ ││││├─┘│ ├┤ ┌┴┬┘ ├┤ ││ │ ├┤ ├┬┘ - // ╚ ╩╚═╩ ╩╚═╝ ╩ ╚═╝╩╚═╚═╝ └─┘└─┘┴ ┴┴ ┴─┘└─┘┴ └─ └ ┴┴─┘┴ └─┘┴└─ + // ╔═╗╦═╗╔═╗╔═╗╔╦╗╦ ╦╦═╗╔═╗ ┌─┐┌─┐┌┬┐┌─┐┬ ┌─┐─┐ ┬ ┌─┐┌─┐┌┐┌┌─┐┌┬┐┬─┐┌─┐┬┌┐┌┌┬┐ + // ╠╣ ╠╦╝╠═╣║ ║ ║ ║╠╦╝║╣ │ │ ││││├─┘│ ├┤ ┌┴┬┘ │ │ ││││└─┐ │ ├┬┘├─┤││││ │ + // ╚ ╩╚═╩ ╩╚═╝ ╩ ╚═╝╩╚═╚═╝ └─┘└─┘┴ ┴┴ ┴─┘└─┘┴ └─ └─┘└─┘┘└┘└─┘ ┴ ┴└─┴ ┴┴┘└┘ ┴ // ┌─ ┬┌─┐ ┬┌┬┐ ┬┌─┐ ┌┬┐┬ ┬┬ ┌┬┐┬ ┬┌─┌─┐┬ ┬ ─┐ // │ │├┤ │ │ │└─┐ ││││ ││ │ │───├┴┐├┤ └┬┘ │ // └─ ┴└ ┴ ┴ ┴└─┘ ┴ ┴└─┘┴─┘┴ ┴ ┴ ┴└─┘ ┴ ─┘