Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'_id' column fix for archiving with mongodb models and schema: true #1601

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/waterline/methods/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ module.exports = function archive(/* criteria, explicitCbMaybe, metaContainer */
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


var defaultWhereCriteria = query.criteria.where;

// ╔═╗═╗ ╦╔═╗╔═╗╦ ╦╔╦╗╔═╗ ┌─┐┬┌┐┌┌┬┐ ┌─┐ ┬ ┬┌─┐┬─┐┬ ┬
// ║╣ ╔╩╦╝║╣ ║ ║ ║ ║ ║╣ ├┤ ││││ ││ │─┼┐│ │├┤ ├┬┘└┬┘
// ╚═╝╩ ╚═╚═╝╚═╝╚═╝ ╩ ╚═╝ └ ┴┘└┘─┴┘ └─┘└└─┘└─┘┴└─ ┴
Expand All @@ -240,6 +242,8 @@ module.exports = function archive(/* criteria, explicitCbMaybe, metaContainer */
});
});//∞

query.criteria.where = defaultWhereCriteria;

// ╔═╗═╗ ╦╔═╗╔═╗╦ ╦╔╦╗╔═╗ ┌─┐┬─┐┌─┐┌─┐┌┬┐┌─┐┌─┐┌─┐┌─┐┬ ┬ ┌─┐ ┬ ┬┌─┐┬─┐┬ ┬
// ║╣ ╔╩╦╝║╣ ║ ║ ║ ║ ║╣ │ ├┬┘├┤ ├─┤ │ ├┤ ├┤ ├─┤│ ├─┤ │─┼┐│ │├┤ ├┬┘└┬┘
// ╚═╝╩ ╚═╚═╝╚═╝╚═╝ ╩ ╚═╝ └─┘┴└─└─┘┴ ┴ ┴ └─┘└─┘┴ ┴└─┘┴ ┴ └─┘└└─┘└─┘┴└─ ┴
Expand All @@ -255,6 +259,8 @@ module.exports = function archive(/* criteria, explicitCbMaybe, metaContainer */
delete query.criteria.select;
delete query.criteria.omit;

query.criteria.where = defaultWhereCriteria;

// ╔═╗═╗ ╦╔═╗╔═╗╦ ╦╔╦╗╔═╗ ┌┬┐┌─┐┌─┐┌┬┐┬─┐┌─┐┬ ┬ ┌─┐ ┬ ┬┌─┐┬─┐┬ ┬
// ║╣ ╔╩╦╝║╣ ║ ║ ║ ║ ║╣ ││├┤ └─┐ │ ├┬┘│ │└┬┘ │─┼┐│ │├┤ ├┬┘└┬┘
// ╚═╝╩ ╚═╚═╝╚═╝╚═╝ ╩ ╚═╝ ─┴┘└─┘└─┘ ┴ ┴└─└─┘ ┴ └─┘└└─┘└─┘┴└─ ┴
Expand Down
1 change: 1 addition & 0 deletions lib/waterline/methods/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'+
Expand Down
4 changes: 2 additions & 2 deletions lib/waterline/utils/query/forge-stage-two-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/waterline/utils/query/private/build-usage-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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!
Expand Down
4 changes: 3 additions & 1 deletion lib/waterline/utils/query/private/normalize-where-clause.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down