From df7d221f3158b475be2bf2417f610c5c0f03ed6c Mon Sep 17 00:00:00 2001 From: Fabien Franzen Date: Sun, 10 May 2015 10:44:22 +0200 Subject: [PATCH] Pass-through options from save to create --- lib/dao.js | 8 ++++---- test/crud-with-options.test.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/dao.js b/lib/dao.js index 9bbaaf55..fdc1cfa8 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -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; diff --git a/test/crud-with-options.test.js b/test/crud-with-options.test.js index fcdaf8c3..a44fcd76 100644 --- a/test/crud-with-options.test.js +++ b/test/crud-with-options.test.js @@ -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);