From 0d6367b11ceb702469e62caf8e8c83a9defbd19b Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Fri, 16 Dec 2016 13:52:31 -0600 Subject: [PATCH 01/25] build up an OR clause for reflexive many to many joins --- lib/waterline/query/dql/destroy.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/waterline/query/dql/destroy.js b/lib/waterline/query/dql/destroy.js index f715d6dd0..b9fd69abb 100644 --- a/lib/waterline/query/dql/destroy.js +++ b/lib/waterline/query/dql/destroy.js @@ -86,17 +86,17 @@ module.exports = function(criteria, cb) { function destroyJoinTableRecords(item, next) { var collection = self.waterline.collections[item]; - var refKey; + var refKey = []; Object.keys(collection._attributes).forEach(function(key) { var attr = collection._attributes[key]; if (attr.references !== self.identity) return; - refKey = key; + refKey.push(key); }); // If no refKey return, this could leave orphaned join table values but it's better // than crashing. - if (!refKey) return next(); + if (!refKey.length) return next(); // Make sure we don't return any undefined pks var mappedValues = result.reduce(function(memo, vals) { @@ -109,7 +109,22 @@ module.exports = function(criteria, cb) { var criteria = {}; if (mappedValues.length > 0) { - criteria[refKey] = mappedValues; + // Handle reflexive associations by building up an OR clause. + if (refKey.length > 1) { + var orCriteria = []; + _.each(refKey, function(columnName) { + var where = {}; + where[columnName] = mappedValues; + orCriteria.push(where); + }); + + criteria = { + or: orCriteria + }; + } else { + criteria[_.first(refKey)] = mappedValues; + } + collection.destroy(criteria).exec(next); } else { return next(); From 0ba6d9169ee6ee6d3c8654d59710dedf4d4e0495 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Fri, 16 Dec 2016 14:10:36 -0600 Subject: [PATCH 02/25] 0.11.7-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d3d8f18c2..bc8e7e4d2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "waterline", "description": "An ORM for Node.js and the Sails framework.", - "version": "0.11.6", + "version": "0.11.7-0", "homepage": "http://waterlinejs.org", "contributors": [ { From d6ddf9182bdb8cd63e333202d9c858633d00d677 Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Tue, 10 Jan 2017 01:58:39 -0600 Subject: [PATCH 03/25] Fixes issue reported in #1429 One to many associations were being removed without checking that the actual related object is the same as the one the user is trying to remove. The fix adds a condition to the update, so that it makes sure that the value matches. --- .gitignore | 1 + .../model/lib/associationMethods/remove.js | 13 +++++++------ .../model/association.remove.hasMany.js | 19 ++++++++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 80ddc0652..fd992ae2f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules .dist coverage/ npm-debug.log +.idea diff --git a/lib/waterline/model/lib/associationMethods/remove.js b/lib/waterline/model/lib/associationMethods/remove.js index 7f46d856c..92d0d37da 100644 --- a/lib/waterline/model/lib/associationMethods/remove.js +++ b/lib/waterline/model/lib/associationMethods/remove.js @@ -43,7 +43,7 @@ var Remove = module.exports = function(collection, proto, records, cb) { // // In the future when transactions are available this will all be done on a single // connection and can be re-written. - this.removeCollectionAssociations(records, cb); + this.removeCollectionAssociations(records, proto, cb); }; /** @@ -78,11 +78,11 @@ Remove.prototype.findPrimaryKey = function(attributes, values) { * @api private */ -Remove.prototype.removeCollectionAssociations = function(records, cb) { +Remove.prototype.removeCollectionAssociations = function(records, proto, cb) { var self = this; async.eachSeries(_.keys(records), function(associationKey, next) { - self.removeAssociations(associationKey, records[associationKey], next); + self.removeAssociations(associationKey, records[associationKey], proto, next); }, function(err) { @@ -103,7 +103,7 @@ Remove.prototype.removeCollectionAssociations = function(records, cb) { * @api private */ -Remove.prototype.removeAssociations = function(key, records, cb) { +Remove.prototype.removeAssociations = function(key, records, proto, cb) { var self = this; // Grab the collection the attribute references @@ -115,7 +115,7 @@ Remove.prototype.removeAssociations = function(key, records, cb) { // Limit Removes to 10 at a time to prevent the connection pool from being exhausted async.eachLimit(records, 10, function(associationId, next) { - self.removeRecord(associatedCollection, schema, associationId, key, next); + self.removeRecord(associatedCollection, schema, associationId, key, proto, next); }, cb); }; @@ -130,7 +130,7 @@ Remove.prototype.removeAssociations = function(key, records, cb) { * @api private */ -Remove.prototype.removeRecord = function(collection, attribute, associationId, key, cb) { +Remove.prototype.removeRecord = function(collection, attribute, associationId, key, proto, cb) { var self = this; // Validate `values` is a correct primary key format @@ -172,6 +172,7 @@ Remove.prototype.removeRecord = function(collection, attribute, associationId, k var _values = {}; criteria[associationKey] = associationId; + criteria[attribute.on] = proto.id; _values[attribute.on] = null; collection.update(criteria, _values, function(err) { diff --git a/test/integration/model/association.remove.hasMany.js b/test/integration/model/association.remove.hasMany.js index 3ad1b0aa9..a83005573 100644 --- a/test/integration/model/association.remove.hasMany.js +++ b/test/integration/model/association.remove.hasMany.js @@ -41,15 +41,18 @@ describe('Model', function() { waterline.loadCollection(Preference); var _values = [ - { id: 1, preference: [{ foo: 'bar' }, { foo: 'foobar' }] }, - { id: 2, preference: [{ foo: 'a' }, { foo: 'b' }] }, + { id: 1, preference: [{ id: 10, foo: 'bar' }, { id: 20, foo: 'foobar' }] }, + { id: 2, preference: [{ id: 30, foo: 'a' }, { id: 40, foo: 'b' }] }, ]; var adapterDef = { find: function(con, col, criteria, cb) { return cb(null, _values); }, update: function(con, col, criteria, values, cb) { if(col === 'preference') { - prefValues.push({ id: criteria.where.id, values: values }); + prefValues.push({ + id: criteria.where.id, + assoc: criteria.where.user, + values: values }); } return cb(null, values); @@ -80,16 +83,18 @@ describe('Model', function() { var person = models[0]; - person.preferences.remove(1); - person.preferences.remove(2); + person.preferences.remove(10); + person.preferences.remove(20); person.save(function(err) { if(err) return done(err); assert(prefValues.length === 2); - assert(prefValues[0].id === 1); + assert(prefValues[0].id === 10); + assert(prefValues[0].assoc === 1); assert(prefValues[0].values.user === null); - assert(prefValues[1].id === 2); + assert(prefValues[1].id === 20); + assert(prefValues[1].assoc === 1); assert(prefValues[1].values.user === null); done(); From 8246a04fee016a6ddb95907e063f6785faaf1e8f Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Tue, 10 Jan 2017 02:58:27 -0600 Subject: [PATCH 04/25] Fixes tests, depending on NPM version installed --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 67847ff20..63c24bb6a 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,23 @@ ROOT=$(shell pwd) +NPMVERSION=$(shell npm --version | cut -f1 -d.) test: test-unit test-integration test-unit: @echo "\nRunning unit tests..." - @NODE_ENV=test mocha test/integration test/structure test/support test/unit --recursive + @NODE_ENV=test node_modules/.bin/mocha test/integration test/structure test/support test/unit --recursive +ifeq "$(NPMVERSION)" "2" test-integration: @echo "\nRunning integration tests..." rm -rf node_modules/waterline-adapter-tests/node_modules/waterline; ln -s "$(ROOT)" node_modules/waterline-adapter-tests/node_modules/waterline; @NODE_ENV=test node test/adapter/runner.js +else +test-integration: + @echo "\nRunning integration tests..." + @NODE_ENV=test node test/adapter/runner.js +endif coverage: @echo "\n\nRunning coverage report..." From 2a7f892d1196a90c59372c13ab77d5cb46aea7e8 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 16 Jan 2017 13:20:58 -0600 Subject: [PATCH 05/25] remove unnecessary early return --- lib/waterline/query/finders/basic.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/waterline/query/finders/basic.js b/lib/waterline/query/finders/basic.js index e688693a1..a19e6244c 100644 --- a/lib/waterline/query/finders/basic.js +++ b/lib/waterline/query/finders/basic.js @@ -123,7 +123,6 @@ module.exports = { if (!hasOwnProperty(search, join.alias)) return; delete search[join.alias]; }); - return; } if (!hasOwnProperty(tmpCriteria, join.alias)) return; @@ -308,7 +307,6 @@ module.exports = { if (!hasOwnProperty(search, join.alias)) return; delete search[join.alias]; }); - return; } if (!hasOwnProperty(tmpCriteria, join.alias)) return; From e5f03720ffdc90260a53b1f4de4f35285354f4fd Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 16 Jan 2017 13:36:54 -0600 Subject: [PATCH 06/25] remove any populates from a count criteria --- lib/waterline/query/dql/count.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/waterline/query/dql/count.js b/lib/waterline/query/dql/count.js index cc628d8a1..ce9a86e33 100644 --- a/lib/waterline/query/dql/count.js +++ b/lib/waterline/query/dql/count.js @@ -56,5 +56,15 @@ module.exports = function(criteria, options, cb) { // Transform Search Criteria criteria = this._transformer.serialize(criteria); + // Remove any joins from the count criteria. They won't have any effect on the + // number of results found. + if (_.isArray(criteria.joins)) { + delete criteria.joins; + } + + if (_.isArray(criteria.where.joins)) { + delete criteria.where.joins; + } + this.adapter.count(criteria, cb); }; From ee30b9446b0341ec277dbf3ea3b237b154d407af Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 16 Jan 2017 13:47:24 -0600 Subject: [PATCH 07/25] ensure criteria piece exists --- lib/waterline/query/dql/count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/waterline/query/dql/count.js b/lib/waterline/query/dql/count.js index ce9a86e33..f4f768b81 100644 --- a/lib/waterline/query/dql/count.js +++ b/lib/waterline/query/dql/count.js @@ -62,7 +62,7 @@ module.exports = function(criteria, options, cb) { delete criteria.joins; } - if (_.isArray(criteria.where.joins)) { + if (criteria.where && _.isArray(criteria.where.joins)) { delete criteria.where.joins; } From bdfdfb88ed0e8beab004e73c53ed4c64afe8a023 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 16 Jan 2017 13:54:54 -0600 Subject: [PATCH 08/25] remove coverage pieces that is failing in travis --- Makefile | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Makefile b/Makefile index 67847ff20..42687054f 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,4 @@ test-integration: ln -s "$(ROOT)" node_modules/waterline-adapter-tests/node_modules/waterline; @NODE_ENV=test node test/adapter/runner.js -coverage: - @echo "\n\nRunning coverage report..." - rm -rf coverage - @NODE_ENV=test ./node_modules/istanbul/lib/cli.js cover --report none --dir coverage/core ./node_modules/.bin/_mocha \ - test/integration test/structure test/support test/unit -- --recursive - ./node_modules/istanbul/lib/cli.js cover --report none --dir coverage/adapter test/adapter/runner.js - ./node_modules/istanbul/lib/cli.js report - -.PHONY: coverage From cd44c1b0fb92b330f5db068db5b0110265679a68 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 16 Jan 2017 13:57:49 -0600 Subject: [PATCH 09/25] remove coverage npm script --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index bc8e7e4d2..3bc945c81 100644 --- a/package.json +++ b/package.json @@ -59,8 +59,7 @@ "scripts": { "test": "make test", "prepublish": "npm prune", - "browserify": "rm -rf .dist && mkdir .dist && browserify lib/waterline.js -s Waterline | uglifyjs > .dist/waterline.min.js", - "coverage": "make coverage" + "browserify": "rm -rf .dist && mkdir .dist && browserify lib/waterline.js -s Waterline | uglifyjs > .dist/waterline.min.js" }, "engines": { "node": ">=0.10.0" From edf79cd7376c4b8c0e40f3a060486cca2823cc56 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 16 Jan 2017 13:58:28 -0600 Subject: [PATCH 10/25] remove after script for travis --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96e1a5106..c9a43c8e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,6 @@ branches: - master - 0.11.x -after_script: - - npm run coverage && cat ./coverage/lcov.info | ./node_modules/.bin/codeclimate - addons: code_climate: repo_token: 351483555263cf9bcd2416c58b0e0ae6ca1b32438aa51bbab2c833560fb67cc0 From 832c4710d442666f7fd2f421392ac28805425869 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 16 Jan 2017 16:10:44 -0600 Subject: [PATCH 11/25] 0.11.7-1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3bc945c81..d4d51a5b4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "waterline", "description": "An ORM for Node.js and the Sails framework.", - "version": "0.11.7-0", + "version": "0.11.7-1", "homepage": "http://waterlinejs.org", "contributors": [ { From f70f43fd180d86ab41def02506a27cd8c6537d21 Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Tue, 17 Jan 2017 11:38:57 -0600 Subject: [PATCH 12/25] 0.11.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d4d51a5b4..a339e7a69 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "waterline", "description": "An ORM for Node.js and the Sails framework.", - "version": "0.11.7-1", + "version": "0.11.7", "homepage": "http://waterlinejs.org", "contributors": [ { From 09a312b098abbc5d6453232db2337e84683b8e65 Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Mon, 23 Jan 2017 08:07:12 -0600 Subject: [PATCH 13/25] Update method by which cacheKey for many-to-many-through queries is derived fixes https://github.com/balderdashy/sails/issues/3946 --- lib/waterline/model/lib/associationMethods/add.js | 2 +- lib/waterline/model/lib/associationMethods/remove.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/waterline/model/lib/associationMethods/add.js b/lib/waterline/model/lib/associationMethods/add.js index 184c6c349..d7d36d766 100644 --- a/lib/waterline/model/lib/associationMethods/add.js +++ b/lib/waterline/model/lib/associationMethods/add.js @@ -295,7 +295,7 @@ Add.prototype.createManyToMany = function(collection, attribute, pk, key, cb) { // If this is a throughTable, look into the meta data cache for what key to use if (collectionAttributes.throughTable) { - var cacheKey = collectionAttributes.throughTable[attribute.on + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key]; + var cacheKey = collectionAttributes.throughTable[self.collection.adapter.identity + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key]; if (!cacheKey) { return cb(new Error('Unable to find the proper cache key in the through table definition')); } diff --git a/lib/waterline/model/lib/associationMethods/remove.js b/lib/waterline/model/lib/associationMethods/remove.js index 7f46d856c..f1acd0634 100644 --- a/lib/waterline/model/lib/associationMethods/remove.js +++ b/lib/waterline/model/lib/associationMethods/remove.js @@ -233,7 +233,7 @@ Remove.prototype.removeManyToMany = function(collection, attribute, pk, key, cb) // If this is a throughTable, look into the meta data cache for what key to use if (collectionAttributes.throughTable) { - var cacheKey = collectionAttributes.throughTable[attribute.on + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key]; + var cacheKey = collectionAttributes.throughTable[self.collection.adapter.identity + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key]; if (!cacheKey) { return cb(new Error('Unable to find the proper cache key in the through table definition')); } From 843b86360754791a15d809d07c7292179009623f Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Wed, 25 Jan 2017 13:37:09 -0600 Subject: [PATCH 14/25] Use NPM-published wl-adapter-tests --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a339e7a69..de372875a 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "mocha": "2.4.5", "sails-memory": "balderdashy/sails-memory", "should": "8.2.1", - "waterline-adapter-tests": "balderdashy/waterline-adapter-tests#0.11.x" + "waterline-adapter-tests": "~0.11.2" }, "keywords": [ "mvc", From dd3b57faef731498f558fa29a2f7ec51aaae89bc Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Wed, 25 Jan 2017 14:12:37 -0600 Subject: [PATCH 15/25] Check adapters for compatibility with Waterline 0.11.x. --- lib/waterline.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/waterline.js b/lib/waterline.js index 2fc426c2d..5875c7c84 100644 --- a/lib/waterline.js +++ b/lib/waterline.js @@ -77,9 +77,27 @@ Waterline.prototype.initialize = function(options, cb) { var self = this; // Ensure a config object is passed in containing adapters - if (!options) throw new Error('Usage Error: function(options, callback)'); - if (!options.adapters) throw new Error('Options object must contain an adapters object'); - if (!options.connections) throw new Error('Options object must contain a connections object'); + if (!options) { throw new Error('Usage Error: function(options, callback)'); } + if (!options.adapters) { throw new Error('Options object must contain an adapters object'); } + if (!options.connections) { throw new Error('Options object must contain a connections object'); } + + // Check that the given adapter is compatible with Waterline 0.11.x. + try { + _.each(options.adapters, function(adapter) { + // Adapters meant for Waterline >= 0.12 will have an adapterApiVersion property, so if we + // see that then we know the adapter won't work with this version of Waterline. + if (!_.isUndefined(adapter.adapterApiVersion)) { + throw new Error( + '\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\n'+ + 'Cannot initialize Waterline.\n'+ + 'The installed version of adapter `' + adapter.identity + '` is too new!\n' + + 'Please try installing a version < 1.0.\n' + + '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\n'); + } + }); + } catch (e) { + return cb(e); + } // Allow collections to be passed in to the initialize method if (options.collections) { From 381dc3859ea0a0096d1a6bb1f0abae37503c4773 Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Wed, 25 Jan 2017 14:51:39 -0600 Subject: [PATCH 16/25] Use tabs in Makefile --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 0f099897b..ca8eec8a7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,6 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[Makefile] +indent_style = tab From de0ae219a0df19b3f2ddb80905b1673f178389c4 Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Wed, 25 Jan 2017 14:52:53 -0600 Subject: [PATCH 17/25] For NPM >= 3, ensure waterline-adapter-tests/node_modules folder exists before symlinking in it --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 42687054f..11c48d0ea 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ test-unit: test-integration: @echo "\nRunning integration tests..." rm -rf node_modules/waterline-adapter-tests/node_modules/waterline; + mkdir -p node_modules/waterline-adapter-tests/node_modules; ln -s "$(ROOT)" node_modules/waterline-adapter-tests/node_modules/waterline; @NODE_ENV=test node test/adapter/runner.js From f64a9161ce7db91ce14e976dbc8477d5b97be3a9 Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Wed, 25 Jan 2017 14:54:55 -0600 Subject: [PATCH 18/25] 0.11.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index de372875a..a4192243b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "waterline", "description": "An ORM for Node.js and the Sails framework.", - "version": "0.11.7", + "version": "0.11.8", "homepage": "http://waterlinejs.org", "contributors": [ { From d824de9400d3ec52acd327df03672e94b22b9ceb Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Wed, 15 Feb 2017 15:30:16 -0600 Subject: [PATCH 19/25] 0.11.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a4192243b..6c04b9a50 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "waterline", "description": "An ORM for Node.js and the Sails framework.", - "version": "0.11.8", + "version": "0.11.9", "homepage": "http://waterlinejs.org", "contributors": [ { From 3b23e5bacb4c883391ec9525c42363aefd9553d7 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 6 Mar 2017 15:18:29 -0600 Subject: [PATCH 20/25] use correct key for through table --- lib/waterline/utils/nestedOperations/update.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/waterline/utils/nestedOperations/update.js b/lib/waterline/utils/nestedOperations/update.js index a2266d20e..c247ebd13 100644 --- a/lib/waterline/utils/nestedOperations/update.js +++ b/lib/waterline/utils/nestedOperations/update.js @@ -411,7 +411,7 @@ function buildParentRemoveOperations(parent, operations) { model: child.identity, criteria: searchCriteria, keyName: attribute.on, - nullify: !hop(child, 'junctionTable') + nullify: !hop(child, 'throughTable') }; From b89d889042e05624d0b793a7ad2b733e8154fdd3 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 6 Mar 2017 15:37:26 -0600 Subject: [PATCH 21/25] loosen range on waterline-schema --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c04b9a50..0bb4cb7d8 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "prompt": "0.2.14", "switchback": "2.0.0", "waterline-criteria": "~0.11.2", - "waterline-schema": "0.2.0" + "waterline-schema": "~0.2.1" }, "devDependencies": { "codeclimate-test-reporter": "0.3.1", From ceb446cade33a8dce0f32388b6bea19dfea37440 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Mon, 6 Mar 2017 15:37:45 -0600 Subject: [PATCH 22/25] 0.11.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0bb4cb7d8..7b46cba6f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "waterline", "description": "An ORM for Node.js and the Sails framework.", - "version": "0.11.9", + "version": "0.11.10", "homepage": "http://waterlinejs.org", "contributors": [ { From 30aa6ef994ab881b7e47e641c13f4ee53bebdfbb Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Wed, 8 Mar 2017 12:56:15 -0600 Subject: [PATCH 23/25] transform values returned from a destroy query if available --- lib/waterline/query/dql/destroy.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/waterline/query/dql/destroy.js b/lib/waterline/query/dql/destroy.js index b9fd69abb..5aae92d5b 100644 --- a/lib/waterline/query/dql/destroy.js +++ b/lib/waterline/query/dql/destroy.js @@ -138,9 +138,25 @@ module.exports = function(criteria, cb) { }); function after() { - callbacks.afterDestroy(self, result, function(err) { + + // If no result was returned, default to empty array + if (!result) { + result = []; + } + + // If values is not an array, return an array + if (!Array.isArray(result)) { + result = [result]; + } + + // Unserialize each value + var transformedValues = result.map(function(value) { + return self._transformer.unserialize(value); + }); + + callbacks.afterDestroy(self, transformedValues, function(err) { if (err) return cb(err); - cb(null, result); + cb(null, transformedValues); }); } From 55c5f0de579f8c2da6485366428c81c673a96b63 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Wed, 8 Mar 2017 13:16:11 -0600 Subject: [PATCH 24/25] fix tests --- test/integration/model/destroy.js | 8 ++++---- test/unit/query/query.destroy.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/integration/model/destroy.js b/test/integration/model/destroy.js index 3e82b34d9..9d15ceca4 100644 --- a/test/integration/model/destroy.js +++ b/test/integration/model/destroy.js @@ -26,7 +26,7 @@ describe('Model', function() { waterline.loadCollection(Collection); - var adapterDef = { destroy: function(con, col, options, cb) { return cb(null, true); }}; + var adapterDef = { destroy: function(con, col, options, cb) { return cb(null, [{ id: 1, first_name: 'foo', last_name: 'bar' }]); }}; var connections = { 'my_foo': { @@ -46,12 +46,12 @@ describe('Model', function() { // TEST METHODS //////////////////////////////////////////////////// - it('should pass status from the adapter destroy method', function(done) { + it('should pass data from the adapter destroy method', function(done) { var person = new collection._model({ id: 1, first_name: 'foo', last_name: 'bar' }); - person.destroy(function(err, status) { + person.destroy(function(err, records) { assert(!err); - assert(status === true); + assert.equal(records[0].last_name, 'bar'); done(); }); }); diff --git a/test/unit/query/query.destroy.js b/test/unit/query/query.destroy.js index 509346d22..8c62d021e 100644 --- a/test/unit/query/query.destroy.js +++ b/test/unit/query/query.destroy.js @@ -95,7 +95,7 @@ describe('Collection Query', function() { waterline.loadCollection(Model); // Fixture Adapter Def - var adapterDef = { destroy: function(con, col, options, cb) { return cb(null, options); }}; + var adapterDef = { destroy: function(con, col, options, cb) { return cb(null, [{ pkColumn: 1, name: 'foo' }]); }}; var connections = { 'foo': { @@ -111,10 +111,10 @@ describe('Collection Query', function() { }); - it('should use the custom primary key when a single value is passed in', function(done) { + it('should transform column names when values are sent back', function(done) { query.destroy(1, function(err, values) { assert(!err); - assert(values.where.pkColumn === 1); + assert.equal(values[0].myPk, 1); done(); }); }); From 7bd345109c1503425c77a3988b48df303c4f2573 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Wed, 8 Mar 2017 13:23:47 -0600 Subject: [PATCH 25/25] 0.11.11 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7b46cba6f..c6c517719 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "waterline", "description": "An ORM for Node.js and the Sails framework.", - "version": "0.11.10", + "version": "0.11.11", "homepage": "http://waterlinejs.org", "contributors": [ {