From 4bb284bb60c3b191752b7f49d21e28453b0a2566 Mon Sep 17 00:00:00 2001 From: Amir Jafarian Date: Sat, 2 Apr 2016 12:20:51 -0400 Subject: [PATCH] Define `patch` aliases *Define `patchOrCreate` as an alias for `updateOrCreate` *Define `PatchAttributes` as an alias for `updateAttributes` --- lib/dao.js | 11 ++++++++--- test/manipulation.test.js | 9 +++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/dao.js b/lib/dao.js index df7eb954..26502452 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -430,7 +430,7 @@ function stillConnecting(dataSource, obj, args) { * otherwise, insert a new record. * * NOTE: No setters, validations, or hooks are applied when using upsert. - * `updateOrCreate` is an alias + * `updateOrCreate` and `patchOrCreate` are aliases * @param {Object} data The model instance data * @param {Object} [options] Options for upsert * @param {Function} cb The callback function (optional). @@ -438,7 +438,9 @@ function stillConnecting(dataSource, obj, args) { // [FIXME] rfeng: This is a hack to set up 'upsert' first so that // 'upsert' will be used as the name for strong-remoting to keep it backward // compatible for angular SDK -DataAccessObject.updateOrCreate = DataAccessObject.upsert = function upsert(data, options, cb) { +DataAccessObject.updateOrCreate = +DataAccessObject.patchOrCreate = +DataAccessObject.upsert = function(data, options, cb) { var connectionPromise = stillConnecting(this.getDataSource(), this, arguments); if (connectionPromise) { return connectionPromise; @@ -2766,13 +2768,16 @@ DataAccessObject.replaceById = function(id, data, options, cb) { /** * Update set of attributes. * Performs validation before updating. + * NOTE: `patchOrCreate` is an alias. * * @trigger `validation`, `save` and `update` hooks * @param {Object} data Data to update * @param {Object} [options] Options for updateAttributes * @param {Function} cb Callback function called with (err, instance) */ -DataAccessObject.prototype.updateAttributes = function updateAttributes(data, options, cb) { +DataAccessObject.prototype.updateAttributes = +DataAccessObject.prototype.patchAttributes = +function(data, options, cb) { var self = this; var connectionPromise = stillConnecting(this.getDataSource(), this, arguments); if (connectionPromise) { diff --git a/test/manipulation.test.js b/test/manipulation.test.js index d72fee38..70d353ab 100644 --- a/test/manipulation.test.js +++ b/test/manipulation.test.js @@ -459,6 +459,11 @@ describe('manipulation', function() { }); }); + it('has an alias "patchAttributes"', function(done) { + person.updateAttributes.should.equal(person.patchAttributes); + done(); + }); + it('should update one attribute', function(done) { person.updateAttribute('name', 'Paul Graham', function(err, p) { if (err) return done(err); @@ -629,6 +634,10 @@ describe('manipulation', function() { }); describe('updateOrCreate', function() { + it('has an alias "patchOrCreate"', function() { + StubUser.updateOrCreate.should.equal(StubUser.patchOrCreate); + }); + it('should preserve properties with dynamic setters on create', function(done) { StubUser.updateOrCreate({ password: 'foo' }, function(err, created) { if (err) return done(err);