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

  1. 22 Nov, 2011 7 commits
  2. 21 Nov, 2011 11 commits
  3. 18 Nov, 2011 7 commits
  4. 17 Nov, 2011 4 commits
  5. 16 Nov, 2011 6 commits
  6. 15 Nov, 2011 2 commits
  7. 14 Nov, 2011 3 commits
    • moved association specs to own file · 957893c6
      Sascha Depold committed
    • Added ability to supply custom validation methods. Each custom validation method… · 56237112
      … recieves the field value to validate as its sole argument. It should throw an error to indicate a validation failure. For example:
      
      <pre>
            User = sequelize.define('User', {
              name: {
                type: Sequelize.STRING,
                validate: {
                    len: {
                      args: 9,
      		msg: "Need atleast 9 chars"
                    },
                    customFn1: function(val) {
                      # if name doesn't start with 'joe' then fail
                      if (val.substr(0,3) !== "joe")
                          throw new Error("name should start with 'joe'")
                    },
                    customFn2: function(val) {
                      # if name doesn't end in 'bloggs' then fail
                      if (val.substr(-6) !== "bloggs")
                          throw new Error("name should end with 'bloggs'")
                    }
                }
              }
            });
      </pre>
      
      You still invoke validation as you normally would, i.e.:
      
      <pre>
      # build user
      var user = User.build({
          name : "test"
      });
      
      # validate
      errors = user.validate();
      # At this point errors will contain:
      #
      # { name : [
      #	"Need atleast 9 chars"
      #	"name should start with 'joe'"
      #	"name should end with 'bloggs'"
      # ] }
      #
      </pre>
      Ram committed