Pass-through options from save to create
This commit is contained in:
parent
d8ecea6111
commit
df7d221f31
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue