Last active
December 17, 2015 23:09
-
-
Save calmdev/5687025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This validation check works: | |
user.validate().success(function() { | |
user.save().success(function(user){ | |
console.log(user); | |
}).error(function(errors) { | |
console.log(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) { | |
app.get('MODELS').User.find({ | |
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