From 6dcbb491b0192d53a8c226e873a57939c5b78da9 Mon Sep 17 00:00:00 2001 From: michael-tomala Date: Tue, 30 Apr 2019 14:04:09 +0200 Subject: [PATCH 1/4] id vs. _id column fix for archiving with mongodb models --- lib/waterline/methods/archive.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/waterline/methods/archive.js b/lib/waterline/methods/archive.js index 9b5020036..07ee6a593 100644 --- a/lib/waterline/methods/archive.js +++ b/lib/waterline/methods/archive.js @@ -216,6 +216,8 @@ module.exports = function archive(/* criteria, explicitCbMaybe, metaContainer */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + var defaultWhereCriteria = query.criteria.where; + // ╔═╗═╗ ╦╔═╗╔═╗╦ ╦╔╦╗╔═╗ ┌─┐┬┌┐┌┌┬┐ ┌─┐ ┬ ┬┌─┐┬─┐┬ ┬ // ║╣ ╔╩╦╝║╣ ║ ║ ║ ║ ║╣ ├┤ ││││ ││ │─┼┐│ │├┤ ├┬┘└┬┘ // ╚═╝╩ ╚═╚═╝╚═╝╚═╝ ╩ ╚═╝ └ ┴┘└┘─┴┘ └─┘└└─┘└─┘┴└─ ┴ @@ -240,6 +242,8 @@ module.exports = function archive(/* criteria, explicitCbMaybe, metaContainer */ }); });//∞ + query.criteria.where = defaultWhereCriteria; + // ╔═╗═╗ ╦╔═╗╔═╗╦ ╦╔╦╗╔═╗ ┌─┐┬─┐┌─┐┌─┐┌┬┐┌─┐┌─┐┌─┐┌─┐┬ ┬ ┌─┐ ┬ ┬┌─┐┬─┐┬ ┬ // ║╣ ╔╩╦╝║╣ ║ ║ ║ ║ ║╣ │ ├┬┘├┤ ├─┤ │ ├┤ ├┤ ├─┤│ ├─┤ │─┼┐│ │├┤ ├┬┘└┬┘ // ╚═╝╩ ╚═╚═╝╚═╝╚═╝ ╩ ╚═╝ └─┘┴└─└─┘┴ ┴ ┴ └─┘└─┘┴ ┴└─┘┴ ┴ └─┘└└─┘└─┘┴└─ ┴ @@ -255,6 +259,8 @@ module.exports = function archive(/* criteria, explicitCbMaybe, metaContainer */ delete query.criteria.select; delete query.criteria.omit; + query.criteria.where = defaultWhereCriteria; + // ╔═╗═╗ ╦╔═╗╔═╗╦ ╦╔╦╗╔═╗ ┌┬┐┌─┐┌─┐┌┬┐┬─┐┌─┐┬ ┬ ┌─┐ ┬ ┬┌─┐┬─┐┬ ┬ // ║╣ ╔╩╦╝║╣ ║ ║ ║ ║ ║╣ ││├┤ └─┐ │ ├┬┘│ │└┬┘ │─┼┐│ │├┤ ├┬┘└┬┘ // ╚═╝╩ ╚═╚═╝╚═╝╚═╝ ╩ ╚═╝ ─┴┘└─┘└─┘ ┴ ┴└─└─┘ ┴ └─┘└└─┘└─┘┴└─ ┴ From a1a493037f6b40e96e4169bda2182a3673f8c7cf Mon Sep 17 00:00:00 2001 From: michael-tomala Date: Thu, 16 Jan 2020 16:55:06 +0100 Subject: [PATCH 2/4] id vs. _id column fix for archiving with mongodb models --- lib/waterline/utils/query/private/normalize-where-clause.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/waterline/utils/query/private/normalize-where-clause.js b/lib/waterline/utils/query/private/normalize-where-clause.js index 2e96b981f..c50de54b4 100644 --- a/lib/waterline/utils/query/private/normalize-where-clause.js +++ b/lib/waterline/utils/query/private/normalize-where-clause.js @@ -516,7 +516,9 @@ module.exports = function normalizeWhereClause(whereClause, modelIdentity, orm, // Normalize the constraint itself. // (note that this checks the RHS, but it also checks the key aka constraint target -- i.e. the attr name) try { - branch[soleBranchKey] = normalizeConstraint(branch[soleBranchKey], soleBranchKey, modelIdentity, orm, meta); + if( '$text' == soleBranchKey ) { + branch[soleBranchKey] = normalizeConstraint(branch[soleBranchKey], soleBranchKey, modelIdentity, orm, meta); + } } catch (e) { switch (e.code) { From 495bebc1989c6d76b2791621d918b3f2cd82dfb3 Mon Sep 17 00:00:00 2001 From: michael-tomala Date: Thu, 16 Jan 2020 16:56:01 +0100 Subject: [PATCH 3/4] id vs. _id column fix for archiving with mongodb models --- lib/waterline/utils/query/private/normalize-where-clause.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/waterline/utils/query/private/normalize-where-clause.js b/lib/waterline/utils/query/private/normalize-where-clause.js index c50de54b4..67e81ba2a 100644 --- a/lib/waterline/utils/query/private/normalize-where-clause.js +++ b/lib/waterline/utils/query/private/normalize-where-clause.js @@ -516,7 +516,7 @@ module.exports = function normalizeWhereClause(whereClause, modelIdentity, orm, // Normalize the constraint itself. // (note that this checks the RHS, but it also checks the key aka constraint target -- i.e. the attr name) try { - if( '$text' == soleBranchKey ) { + if( '$text' !== soleBranchKey ) { branch[soleBranchKey] = normalizeConstraint(branch[soleBranchKey], soleBranchKey, modelIdentity, orm, meta); } } catch (e) { From 3815680d92c6bb90f1081c4298457849bf983d67 Mon Sep 17 00:00:00 2001 From: michael-tomala Date: Sat, 19 Jun 2021 12:01:00 +0200 Subject: [PATCH 4/4] id vs. _id column fix for archiving with mongodb models --- lib/waterline/methods/create.js | 1 + lib/waterline/utils/query/forge-stage-two-query.js | 4 ++-- lib/waterline/utils/query/private/build-usage-error.js | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/waterline/methods/create.js b/lib/waterline/methods/create.js index c6c60742a..645623652 100644 --- a/lib/waterline/methods/create.js +++ b/lib/waterline/methods/create.js @@ -157,6 +157,7 @@ module.exports = function create(newRecord, explicitCbMaybe, metaContainer) { name: 'UsageError', code: e.code, details: e.details, + attrName: e.attrName, message: 'Invalid new record.\n'+ 'Details:\n'+ diff --git a/lib/waterline/utils/query/forge-stage-two-query.js b/lib/waterline/utils/query/forge-stage-two-query.js index 6fd6ea1f6..7fe5eda74 100644 --- a/lib/waterline/utils/query/forge-stage-two-query.js +++ b/lib/waterline/utils/query/forge-stage-two-query.js @@ -1254,10 +1254,10 @@ module.exports = function forgeStageTwoQuery(query, orm) { case 'E_TYPE': case 'E_REQUIRED': case 'E_VIOLATES_RULES': - throw buildUsageError('E_INVALID_NEW_RECORD', e.message, query.using); + throw buildUsageError('E_INVALID_NEW_RECORD', e.message, query.using, e.attrName); case 'E_HIGHLY_IRREGULAR': - throw buildUsageError('E_INVALID_NEW_RECORD', e.message, query.using); + throw buildUsageError('E_INVALID_NEW_RECORD', e.message, query.using, e.attrName); default: throw e; } diff --git a/lib/waterline/utils/query/private/build-usage-error.js b/lib/waterline/utils/query/private/build-usage-error.js index fdc2c15d8..2511d82fd 100644 --- a/lib/waterline/utils/query/private/build-usage-error.js +++ b/lib/waterline/utils/query/private/build-usage-error.js @@ -153,7 +153,7 @@ var USAGE_ERR_MSG_TEMPLATES = { * > this utility adds another internal item to the top of the trace. */ -module.exports = function buildUsageError(code, details, modelIdentity) { +module.exports = function buildUsageError(code, details, modelIdentity, attrName) { // Sanity checks if (!_.isString(code)) { @@ -187,7 +187,8 @@ module.exports = function buildUsageError(code, details, modelIdentity) { name: 'UsageError', code: code, details: details, - modelIdentity: modelIdentity + modelIdentity: modelIdentity, + attrName: attrName }, err); // That's it!