Define `patch` aliases

*Define `patchOrCreate` as an alias for `updateOrCreate`
*Define `PatchAttributes` as an alias for `updateAttributes`
This commit is contained in:
Amir Jafarian 2016-04-02 12:20:51 -04:00
parent 7eee0afb52
commit 7773963b62
2 changed files with 19 additions and 5 deletions

View File

@ -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) {

View File

@ -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);