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

Commit 2239d570 by Sushant Committed by GitHub

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

1 parent d65cc7bc
...@@ -1672,13 +1672,12 @@ class Model { ...@@ -1672,13 +1672,12 @@ class Model {
tableNames[this.getTableName(options)] = true; tableNames[this.getTableName(options)] = true;
options = Utils.cloneDeep(options); options = Utils.cloneDeep(options);
_.defaults(options, { _.defaults(options, { hooks: true });
hooks: true,
rejectOnEmpty: this.options.rejectOnEmpty
});
// set rejectOnEmpty option from model config // set rejectOnEmpty option, defaults to model options
options.rejectOnEmpty = options.rejectOnEmpty || this.options.rejectOnEmpty; options.rejectOnEmpty = options.hasOwnProperty('rejectOnEmpty')
? options.rejectOnEmpty
: this.options.rejectOnEmpty;
return Promise.try(() => { return Promise.try(() => {
this._injectScope(options); this._injectScope(options);
...@@ -1904,8 +1903,7 @@ class Model { ...@@ -1904,8 +1903,7 @@ class Model {
// Bypass a possible overloaded findAll. // Bypass a possible overloaded findAll.
return this.findAll(_.defaults(options, { return this.findAll(_.defaults(options, {
plain: true, plain: true
rejectOnEmpty: false
})); }));
} }
......
...@@ -976,6 +976,24 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -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', () => { it('resolve null when disabled', () => {
const Model = current.define('Test', { const Model = current.define('Test', {
username: Sequelize.STRING(100) username: Sequelize.STRING(100)
......
...@@ -1658,7 +1658,6 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1658,7 +1658,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('throws custom error with initialized', () => { it('throws custom error with initialized', () => {
const Model = current.define('Test', { const Model = current.define('Test', {
username: Sequelize.STRING(100) username: Sequelize.STRING(100)
}, { }, {
...@@ -1676,7 +1675,6 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1676,7 +1675,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('throws custom error with instance', () => { it('throws custom error with instance', () => {
const Model = current.define('Test', { const Model = current.define('Test', {
username: Sequelize.STRING(100) username: Sequelize.STRING(100)
}, { }, {
...@@ -1692,7 +1690,5 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1692,7 +1690,5 @@ describe(Support.getTestDialectTeaser('Model'), () => {
})).to.eventually.be.rejectedWith(Sequelize.ConnectionError); })).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!