不要怂,就是干,撸起袖子干!

Commit 2239d570 by Sushant Committed by GitHub

fix(model): unable to override rejectOnEmpty (#9632)

1 parent d65cc7bc
......@@ -1672,13 +1672,12 @@ class Model {
tableNames[this.getTableName(options)] = true;
options = Utils.cloneDeep(options);
_.defaults(options, {
hooks: true,
rejectOnEmpty: this.options.rejectOnEmpty
});
_.defaults(options, { hooks: true });
// set rejectOnEmpty option from model config
options.rejectOnEmpty = options.rejectOnEmpty || this.options.rejectOnEmpty;
// set rejectOnEmpty option, defaults to model options
options.rejectOnEmpty = options.hasOwnProperty('rejectOnEmpty')
? options.rejectOnEmpty
: this.options.rejectOnEmpty;
return Promise.try(() => {
this._injectScope(options);
......@@ -1904,8 +1903,7 @@ class Model {
// Bypass a possible overloaded findAll.
return this.findAll(_.defaults(options, {
plain: true,
rejectOnEmpty: false
plain: true
}));
}
......
......@@ -976,6 +976,24 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it('override model options', () => {
const Model = current.define('Test', {
username: Sequelize.STRING(100)
}, {
rejectOnEmpty: true
});
return Model.sync({ force: true })
.then(() => {
return expect(Model.findOne({
rejectOnEmpty: false,
where: {
username: 'some-username-that-is-not-used-anywhere'
}
})).to.eventually.be.deep.equal(null);
});
});
it('resolve null when disabled', () => {
const Model = current.define('Test', {
username: Sequelize.STRING(100)
......
......@@ -1658,7 +1658,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
it('throws custom error with initialized', () => {
const Model = current.define('Test', {
username: Sequelize.STRING(100)
}, {
......@@ -1676,7 +1675,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
it('throws custom error with instance', () => {
const Model = current.define('Test', {
username: Sequelize.STRING(100)
}, {
......@@ -1692,7 +1690,5 @@ describe(Support.getTestDialectTeaser('Model'), () => {
})).to.eventually.be.rejectedWith(Sequelize.ConnectionError);
});
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!