Pass-through options from save to create

This commit is contained in:
Fabien Franzen 2015-05-10 10:44:22 +02:00
parent d8ecea6111
commit df7d221f31
2 changed files with 25 additions and 4 deletions

View File

@ -1635,6 +1635,10 @@ DataAccessObject.prototype.save = function (options, cb) {
assert(typeof options === 'object', 'The options argument should be an object');
assert(typeof cb === 'function', 'The cb argument should be a function');
if (this.isNewRecord()) {
return Model.create(this, options, cb);
}
var hookState = {};
if (options.validate === undefined) {
@ -1644,10 +1648,6 @@ DataAccessObject.prototype.save = function (options, cb) {
options.throws = false;
}
if (this.isNewRecord()) {
return Model.create(this, cb);
}
var inst = this;
var modelName = Model.modelName;

View File

@ -408,6 +408,27 @@ describe('crud-with-options', function () {
});
describe('save', function () {
it('should allow save(options, cb)', function (done) {
var options = { foo: 'bar' };
var opts;
User.observe('after save', function(ctx, next) {
opts = ctx.options;
next();
});
var u = new User();
u.save(options, function(err) {
should.not.exist(err);
options.should.equal(opts);
done();
});
});
});
describe('destroyAll with options', function () {
beforeEach(seed);