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

Commit 66ac75f6 by Sushant

using rejectOnEmpty option name, changelog

1 parent 8ff99286
# Future
- [ADDED] rejectOnEmpty mode [#272](https://github.com/sequelize/sequelize/issues/272) [#5480](https://github.com/sequelize/sequelize/issues/5480)
- [ADDED] `beforeCount` hook [#5209](https://github.com/sequelize/sequelize/pull/5209)
- [ADDED] `validationFailed` hook [#1626](https://github.com/sequelize/sequelize/issues/1626)
- [FIXED] Mark index as `unique: true` when `type: 'UNIQUE'`. Fixes [#5351](https://github.com/sequelize/sequelize/issues/5351)
......
......@@ -301,7 +301,7 @@ error.InstanceError = function (message) {
util.inherits(error.InstanceError, error.BaseError);
/**
* Thrown when a record was not found, Usually used with kenophobic mode (see message for details)
* Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details)
* @extends BaseError
* @constructor
*/
......
......@@ -35,7 +35,7 @@ var Model = function(name, attributes, options) {
underscored: false,
underscoredAll: false,
paranoid: false,
kenophobic: false,
rejectOnEmpty: false,
whereCollection: null,
schema: null,
schemaDelimiter: '',
......@@ -1335,7 +1335,7 @@ Model.prototype.all = function(options) {
* @param {Object} [options.having]
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {Boolean} [options.benchmark=false] Print query execution time in milliseconds when logging SQL.
* @param {Boolean|Error Instance} [options.kenophobic=false] Throws error when no record is found
* @param {Boolean|Error Instance} [options.rejectOnEmpty=false] Throws an error when no records found
*
* @see {Sequelize#query}
* @return {Promise<Array<Instance>>}
......@@ -1356,10 +1356,10 @@ Model.prototype.findAll = function(options) {
tableNames[this.getTableName(options)] = true;
options = optClone(options);
_.defaults(options, { hooks: true, kenophobic: false });
_.defaults(options, { hooks: true, rejectOnEmpty: this.options.rejectOnEmpty });
//set kenophobic option from model config
options.kenophobic = options.kenophobic || this.options.kenophobic;
//set rejectOnEmpty option from model config
options.rejectOnEmpty = options.rejectOnEmpty || this.options.rejectOnEmpty;
return Promise.bind(this).then(function() {
conformOptions(options, this);
......@@ -1411,12 +1411,12 @@ Model.prototype.findAll = function(options) {
}
}).then(function (results) {
//kenophobic mode
if (_.isEmpty(results) && options.kenophobic) {
if (typeof options.kenophobic === 'function') {
throw new options.kenophobic();
} else if (typeof options.kenophobic === 'object') {
throw options.kenophobic;
//rejectOnEmpty mode
if (_.isEmpty(results) && options.rejectOnEmpty) {
if (typeof options.rejectOnEmpty === 'function') {
throw new options.rejectOnEmpty();
} else if (typeof options.rejectOnEmpty === 'object') {
throw options.rejectOnEmpty;
} else {
throw new sequelizeErrors.EmptyResultError();
}
......@@ -1535,7 +1535,7 @@ Model.prototype.findOne = function(options) {
// Bypass a possible overloaded findAll.
return Model.prototype.findAll.call(this, _.defaults(options, {
plain: true,
kenophobic: false
rejectOnEmpty: false
}));
};
Model.prototype.find = Model.prototype.findOne;
......
......@@ -442,7 +442,7 @@ Sequelize.prototype.InstanceError = Sequelize.InstanceError =
sequelizeErrors.InstanceError;
/**
* Thrown when a record was not found, Usually used with kenophobic mode (see message for details)
* Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details)
* @see {Errors#RecordNotFoundError}
*/
Sequelize.prototype.EmptyResultError = Sequelize.EmptyResultError =
......
......@@ -936,19 +936,19 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
describe('kenophobic mode', function() {
describe('rejectOnEmpty mode', function() {
it('throws error when record not found by findOne', function() {
return expect(this.User.findOne({
where: {
username: 'ath-kantam-pradakshnami'
},
kenophobic: true
rejectOnEmpty: true
})).to.eventually.be.rejectedWith(Sequelize.EmptyResultError);
});
it('throws error when record not found by findById', function() {
return expect(this.User.findById(4732322332323333232344334354234, {
kenophobic: true
rejectOnEmpty: true
})).to.eventually.be.rejectedWith(Sequelize.EmptyResultError);
});
......@@ -957,7 +957,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
where: {
username: 'some-username-that-is-not-used-anywhere'
},
kenophobic: true
rejectOnEmpty: true
})).to.eventually.be.rejectedWith(Sequelize.EmptyResultError);
});
......@@ -965,7 +965,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var Model = current.define('Test', {
username: Sequelize.STRING(100)
},{
kenophobic: true
rejectOnEmpty: true
});
return Model.sync({ force: true })
......
......@@ -1390,12 +1390,12 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
describe('kenophobic mode', function() {
describe('rejectOnEmpty mode', function() {
it('works from model options', function() {
var Model = current.define('Test', {
username: Sequelize.STRING(100)
},{
kenophobic: true
rejectOnEmpty: true
});
return Model.sync({ force: true })
......@@ -1413,7 +1413,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var Model = current.define('Test', {
username: Sequelize.STRING(100)
},{
kenophobic: new Sequelize.ConnectionError('Some Error') //using custom error instance
rejectOnEmpty: new Sequelize.ConnectionError('Some Error') //using custom error instance
});
return Model.sync({ force: true })
......@@ -1431,7 +1431,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var Model = current.define('Test', {
username: Sequelize.STRING(100)
},{
kenophobic: Sequelize.ConnectionError //using custom error instance
rejectOnEmpty: Sequelize.ConnectionError //using custom error instance
});
return Model.sync({ force: true })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!