Skip to content

Commit

Permalink
Setup for more nuanced object cloning, and a few tweaks to outdated c…
Browse files Browse the repository at this point in the history
…omments. (This is also somewhat related to #1519)
  • Loading branch information
mikermcneil committed Oct 1, 2017
1 parent 65eff72 commit 4d960d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/waterline/utils/query/forge-stage-two-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion lib/waterline/utils/query/private/normalize-criteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/waterline/utils/query/private/normalize-where-clause.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

// ╔═╗╦═╗╔═╗╔═╗╔╦╗╦ ╦╦═╗╔═╗ ┌─┐┌─┐┌┬┐┌─┐┬ ┌─┐─┐ ┬ ┌─┐┬┬ ┌┬┐┌─┐┬─
// ╠╣ ╠╦╝╠═╣║ ║ ║ ║╠╦╝║╣ │ │ ││││├─┘│ ├┤ ┌┴┬┘ ├┤ ││ │ ├┤ ├┬┘
// ╚ ╩╚═╩ ╩╚═╝ ╩ ╚═╝╩╚═╚═╝ └─┘└─┘┴ ┴┴ ┴─┘└─┘┴ └─ └ ┴┴─┘┴ └─┘┴└─
// ╔═╗╦═╗╔═╗╔═╗╔╦╗╦ ╦╦═╗╔═╗ ┌─┐┌─┐┌┬┐┌─┐┬ ┌─┐─┐ ┬ ┌─┐┌─┐┌┐┌┌─┐┌┬┐┬─┐┌─┐┬┌┐┌┌┬
// ╠╣ ╠╦╝╠═╣║ ║ ║ ║╠╦╝║╣ │ │ ││││├─┘│ ├┤ ┌┴┬┘ │ │ ││││└─┐ │ ├┬┘├─┤││││ │
// ╚ ╩╚═╩ ╩╚═╝ ╩ ╚═╝╩╚═╚═╝ └─┘└─┘┴ ┴┴ ┴─┘└─┘┴ └─ └─┘└─┘┘└┘└─┘ ┴ ┴└─┴ ┴┴┘└┘ ┴
// ┌─ ┬┌─┐ ┬┌┬┐ ┬┌─┐ ┌┬┐┬ ┬┬ ┌┬┐┬ ┬┌─┌─┐┬ ┬ ─┐
// │ │├┤ │ │ │└─┐ ││││ ││ │ │───├┴┐├┤ └┬┘ │
// └─ ┴└ ┴ ┴ ┴└─┘ ┴ ┴└─┘┴─┘┴ ┴ ┴ ┴└─┘ ┴ ─┘
Expand Down

0 comments on commit 4d960d9

Please sign in to comment.