leepowelldev / mongoose-validator

Validators for mongoose models utilising validator.js
MIT License
379 stars 43 forks source link

Bind validator scope to `this` #29

Closed jrouleau closed 9 years ago

jrouleau commented 9 years ago

Allows users to access the mongoose validate scope from within a custom validator function.

Example:

var mongoose = require("mongoose");
var validate = require("mongoose-validator");

var MySchema = new mongoose.Schema({
  path: {
    type: String,
    validate: [
      validate({
        validator: function (val) {
          if (!this.isModified("path")) {
            return true;
          }
          // ...
        },
        message: "Invalid ..."
      })
    ]
  }
});
leepowelldev commented 9 years ago

Thanks for this. Would you mind adding a test or two and I'll get this merged in.

leepowelldev commented 9 years ago

This has been merged in with the latest patch update