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

Commit 05a02f7c by Jozef Hartinger Committed by Jan Aagaard Meier

Better validation of attribute definitions (#6200)

1 parent e2e77ae0
......@@ -1037,7 +1037,10 @@ const QueryGenerator = {
return this.handleSequelizeMethod(attr);
}
if (Array.isArray(attr) && attr.length === 2) {
if (Array.isArray(attr)) {
if (attr.length !== 2) {
throw new Error(JSON.stringify(attr) + ' is not a valid attribute definition. Please use the following format: [\'attribute definition\', \'alias\']');
}
attr = attr.slice();
if (attr[0]._isSequelizeMethod) {
......
......@@ -155,6 +155,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
it('should fail with meaningful error message on invalid attributes definition', function() {
expect(this.User.findOne({
where: { id: 1 },
attributes: ['id', ['username']]
})).to.be.rejectedWith('["username"] is not a valid attribute definition. Please use the following format: [\'attribute definition\', \'alias\']');
});
it('should not try to convert boolean values if they are not selected', function() {
var UserWithBoolean = this.sequelize.define('UserBoolean', {
active: Sequelize.BOOLEAN
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!