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.
|
||||
*
|
||||
* 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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue