Define `patch` aliases
*Define `patchOrCreate` as an alias for `updateOrCreate` *Define `PatchAttributes` as an alias for `updateAttributes`
This commit is contained in:
parent
7eee0afb52
commit
7773963b62
11
lib/dao.js
11
lib/dao.js
|
@ -430,7 +430,7 @@ function stillConnecting(dataSource, obj, args) {
|
||||||
* otherwise, insert a new record.
|
* otherwise, insert a new record.
|
||||||
*
|
*
|
||||||
* NOTE: No setters, validations, or hooks are applied when using upsert.
|
* 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} data The model instance data
|
||||||
* @param {Object} [options] Options for upsert
|
* @param {Object} [options] Options for upsert
|
||||||
* @param {Function} cb The callback function (optional).
|
* @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
|
// [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
|
// 'upsert' will be used as the name for strong-remoting to keep it backward
|
||||||
// compatible for angular SDK
|
// 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);
|
var connectionPromise = stillConnecting(this.getDataSource(), this, arguments);
|
||||||
if (connectionPromise) {
|
if (connectionPromise) {
|
||||||
return connectionPromise;
|
return connectionPromise;
|
||||||
|
@ -2758,13 +2760,16 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
|
||||||
/**
|
/**
|
||||||
* Update set of attributes.
|
* Update set of attributes.
|
||||||
* Performs validation before updating.
|
* Performs validation before updating.
|
||||||
|
* NOTE: `patchOrCreate` is an alias.
|
||||||
*
|
*
|
||||||
* @trigger `validation`, `save` and `update` hooks
|
* @trigger `validation`, `save` and `update` hooks
|
||||||
* @param {Object} data Data to update
|
* @param {Object} data Data to update
|
||||||
* @param {Object} [options] Options for updateAttributes
|
* @param {Object} [options] Options for updateAttributes
|
||||||
* @param {Function} cb Callback function called with (err, instance)
|
* @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 self = this;
|
||||||
var connectionPromise = stillConnecting(this.getDataSource(), this, arguments);
|
var connectionPromise = stillConnecting(this.getDataSource(), this, arguments);
|
||||||
if (connectionPromise) {
|
if (connectionPromise) {
|
||||||
|
|
|
@ -459,8 +459,13 @@ describe('manipulation', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update one attribute', function (done) {
|
it('has an alias "patchAttributes"', function(done) {
|
||||||
person.updateAttribute('name', 'Paul Graham', function (err, p) {
|
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);
|
if (err) return done(err);
|
||||||
Person.all(function (e, ps) {
|
Person.all(function (e, ps) {
|
||||||
if (e) return done(e);
|
if (e) return done(e);
|
||||||
|
@ -629,6 +634,10 @@ describe('manipulation', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateOrCreate', 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) {
|
it('should preserve properties with dynamic setters on create', function(done) {
|
||||||
StubUser.updateOrCreate({ password: 'foo' }, function(err, created) {
|
StubUser.updateOrCreate({ password: 'foo' }, function(err, created) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
Loading…
Reference in New Issue