Skip to content

Instantly share code, notes, and snippets.

@calmdev calmdev/validation.js
Last active Dec 17, 2015

What would you like to do?
// This validation check works:
user.validate().success(function() {{
}).error(function(errors) {
// Still trying to get this isUnique validation method working on my model:
email: {
type: DataTypes.STRING,
validate: {
isEmail: {
msg: 'Invalid email address.'
isUnique: function(value) {
where: { email: value }
}).success(function(account) {
throw new Error('Email is already registered.'); // Alone, this line works fine.
// When the isUnique is added to my model, calling .validate(); generates:
Error: Email is already registered.
at null.<anonymous> (/Web/models/User.js:82:13)
at EventEmitter.emit (events.js:95:17)
at null.<anonymous> (/Code/sequelize/lib/query-interface.js:392:17)
at EventEmitter.emit (events.js:117:20)
at null.<anonymous> (/Code/sequelize/lib/dialects/mysql/query.js:32:14)
at Query.Sequence.end (/Code/sequelize/node_modules/mysql/lib/protocol/sequences/Sequence.js:66:24)
at Query._handleFinalResultPacket (/Code/sequelize/node_modules/mysql/lib/protocol/sequences/Query.js:143:8)
at Query.EofPacket (/Code/sequelize/node_modules/mysql/lib/protocol/sequences/Query.js:127:8)
at Protocol._parsePacket (/Code/sequelize/node_modules/mysql/lib/protocol/Protocol.js:172:24)
at Parser.write (/Code/sequelize/node_modules/mysql/lib/protocol/Parser.js:62:12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.