diff --git a/lib/dao.js b/lib/dao.js index e9ac6123..d4ecd134 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; @@ -2758,13 +2760,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 f24897ef..1dc2d358 100644 --- a/test/manipulation.test.js +++ b/test/manipulation.test.js @@ -459,8 +459,13 @@ describe('manipulation', function () { }); }); - it('should update one attribute', function (done) { - person.updateAttribute('name', 'Paul Graham', function (err, p) { + 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); Person.all(function (e, ps) { if (e) return done(e); @@ -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);