Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an error message when a value for array has not been defined #9649

Merged
merged 5 commits into from Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/sequelize.js
Expand Up @@ -1095,9 +1095,14 @@ class Sequelize {
type = dialectTypes[type.key].extend(type);
}

if (type instanceof DataTypes.ARRAY && dialectTypes[type.type.key]) {
type.type = dialectTypes[type.type.key].extend(type.type);
if (type instanceof DataTypes.ARRAY) {
if (!type.type) {
throw new Error('ARRAY is missing type definition for its values.');
} else if (dialectTypes[type.type.key]) {
type.type = dialectTypes[type.type.key].extend(type.type);
}
}

return type;
}

Expand Down
10 changes: 10 additions & 0 deletions test/integration/sequelize.test.js
Expand Up @@ -1205,6 +1205,16 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
});
});

describe('define', () => {
it('raises an error if no values are defined', function() {
expect(() => {
this.sequelize.define('omnomnom', {
bla: { type: DataTypes.ARRAY }
});
}).to.throw(Error, 'ARRAY is missing type definition for its values.');
});
});

describe('define', () => {
[
{ type: DataTypes.ENUM, values: ['scheduled', 'active', 'finished']},
Expand Down