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

  1. 16 Nov, 2011 5 commits
  2. 15 Nov, 2011 2 commits
  3. 14 Nov, 2011 4 commits
  4. 13 Nov, 2011 1 commit
  5. 12 Nov, 2011 6 commits
    • lol@english · 98bd1f44
      Sascha Depold committed
    • fixed travis notification · 75bffb1e
      Sascha Depold committed
    • Added validation to models using node-validator (https://github.com/chriso/node-validator). · 841ab0ce
      To validate your models first define the validation for each field. For example:
      
      <pre>
      var User = sequelize.define 'User', {
              id: {
                  type: Sequelize.INTEGER,
                  autoIncrement: true,
                  primaryKey: true,
      	},
              name: {
                  type: Sequelize.STRING,
                  allowNull: false,
                  unique: true,
                  validate: {
                      len: {
                          args: 3,
                          msg: "Name must be atleast 3 characters in length"
      		}
      	    }
      	},
              email: {
                  type: Sequelize.STRING,
                  allowNull: false,
                  unique: true,
                  validate: {
                      len: {
                          args: [6, 128],
                          msg: "Email address must be between 6 and 128 characters in length"
      		},
                      isEmail: {
                          msg: "Email address must be valid"
      		}
      	    }
      	},
              password: {
                  type: Sequelize.STRING,
                  allowNull: false,
                  validate: {
                      len: {
                          args: 3
      		}
      	    }
      	}
      }
      </pre>
      
      Any of the basic validation methods provided by the node-validation can be specified along with arguments, as shown above. The 'msg' key specifies the error message to return for a given validation if it fails. If this isn't provided then a default generic error message will be returned by the validation library.
      
      To actually perform the validation, call the validate() method on your model instance once your model has been built. For example:
      
      <pre>
      # build user
      var user = User.build({
          name : "test"
          email : "test"
          password : "test"
      });
      
      # validate
      errors = user.validate();
      if (errors)
          # errors is an object with the following structure:
          # { field name : [list of validation failure messages]
          for (var prop in errors) {
              if (errors.hasOwnProperty(prop))
      		console.log("Errors for field " + prop + ": ");
      		for (var i=0; i<errors[prop].length; ++i) {
      			console.log("\t" + errors[prop][i]);
      		}
          }
      else
          # errors is null, which means validation succeeded
      </pre>
      Ram committed
  6. 11 Nov, 2011 1 commit
  7. 10 Nov, 2011 9 commits
  8. 09 Nov, 2011 9 commits
  9. 08 Nov, 2011 3 commits