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

Commit 530d0102 by Jan Aagaard Meier

Exposed validator.js directly, instead of through DaoValidator. Closes #1659

1 parent c7a4220c
...@@ -49,7 +49,8 @@ var options = { ...@@ -49,7 +49,8 @@ var options = {
javadoc.isMixin = getTag(javadoc.raw.tags, 'mixin') !== undefined; javadoc.isMixin = getTag(javadoc.raw.tags, 'mixin') !== undefined;
javadoc.isProperty = getTag(javadoc.raw.tags, 'property') !== undefined javadoc.isProperty = getTag(javadoc.raw.tags, 'property') !== undefined
javadoc.private = getTag(javadoc.raw.tags, 'private') !== undefined javadoc.private = getTag(javadoc.raw.tags, 'private') !== undefined
javadoc.since = getTag(javadoc.raw.tags, 'since');
// Only show params without a dot in them (dots means attributes of object, so no need to clutter the signature too much) // Only show params without a dot in them (dots means attributes of object, so no need to clutter the signature too much)
var params = [] var params = []
javadoc.paramTags.forEach(function (paramTag) { javadoc.paramTags.forEach(function (paramTag) {
......
...@@ -63,6 +63,9 @@ ...@@ -63,6 +63,9 @@
<? if (comment.aliases) { ?> <? if (comment.aliases) { ?>
__Aliases:__ *<?= comment.aliases ?>* __Aliases:__ *<?= comment.aliases ?>*
<? } ?> <? } ?>
<? if (comment.since) { ?>
__Since:__ *<?= comment.since.string ?>*
<? } ?>
====== ======
<? } ?> <? } ?>
<? }) ?> <? }) ?>
......
...@@ -965,6 +965,7 @@ module.exports = (function() { ...@@ -965,6 +965,7 @@ module.exports = (function() {
* @deprecated The syntax is due for change, in order to make `where` more consistent with the rest of the API * @deprecated The syntax is due for change, in order to make `where` more consistent with the rest of the API
* *
* @return {Promise} * @return {Promise}
* @method
* @alias findOrBuild * @alias findOrBuild
*/ */
DAOFactory.prototype.findOrInitialize = DAOFactory.prototype.findOrBuild = function (params, defaults, options) { DAOFactory.prototype.findOrInitialize = DAOFactory.prototype.findOrBuild = function (params, defaults, options) {
......
...@@ -30,7 +30,7 @@ module.exports = (function() { ...@@ -30,7 +30,7 @@ module.exports = (function() {
* *
* #### Example usage * #### Example usage
* *
* ```javascript * ```javascript
* // without password and options * // without password and options
* var sequelize = new Sequelize('database', 'username') * var sequelize = new Sequelize('database', 'username')
* *
...@@ -179,11 +179,11 @@ module.exports = (function() { ...@@ -179,11 +179,11 @@ module.exports = (function() {
Sequelize.QueryTypes = QueryTypes Sequelize.QueryTypes = QueryTypes
/** /**
* The class used to validate attributes of an instance before saving. Validations are carried out using validator.js, and you can use `Sequelize.DAOValidator.Validator` to access the validator.js object and extend it with custom validation functions. * Exposes the validator.js object, so you can extend it with custom validation functions. The validator is exposed both on the instance, and on the constructor.
* @property DAOValidator * @property Validator
* @see https://github.com/chriso/validator.js * @see https://github.com/chriso/validator.js
*/ */
Sequelize.DAOValidator = DAOValidator Sequelize.prototype.Validator = Sequelize.Validator = require('validator')
Sequelize.DAOFactory = Sequelize.Model = DAOFactory Sequelize.DAOFactory = Sequelize.Model = DAOFactory
......
...@@ -836,5 +836,32 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() { ...@@ -836,5 +836,32 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
done() done()
}) })
}) })
it('allows me to add custom validation functions to validator.js', function () {
this.sequelize.Validator.extend('isExactly7Characters', function (val) {
return val.length === 7
})
var User = this.sequelize.define('User', {
name: {
type: Sequelize.STRING,
validate: {
isExactly7Characters: true
}
}
})
return User.build({
name: 'abcdefg'
}).validate().then(function (errors) {
expect(errors === undefined).to.be.ok
return User.build({
name: 'a'
}).validate()
}).then(function (errors) {
expect(errors.name[0].message).to.equal('Validation isExactly7Characters failed')
})
})
}) })
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!