Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is model validation rule missing in v0.12.1 (Error: Unknown rule: is) #3649

Closed
jpbecotte opened this issue Mar 10, 2016 · 7 comments
Closed
Labels
bug orm Related to models, datastores, orm config, Waterline, sails-hook-orm, etc.

Comments

@jpbecotte
Copy link

Sails version: 0.12.1
Node version: v4.4.0
NPM version: 2.14.20
Operating system: Windows 7


Model validation "is" doesn't work.

module.exports = {
  attributes: {
    code: {
        type: 'string',
        required: true,
        is: /$[A-Z]+\d+^/
    },
    title: {
        type: 'string',
        required: true
    },
    suggestedPrice: {
        type: 'float'
    },
    currentInventory: {
        type: 'float'
    }
  }
};

So add the is validation in any attribute. Then it gives the following error:

C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\anchor\lib\match\matchRule.js:37
    throw new Error('Unknown rule: ' + ruleName);
    ^

Error: Unknown rule: is
    at Object.matchRule (C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\anchor\lib\match\matchRule.js:37:11)
    at Anchor.to (C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\anchor\index.js:106:48)
    at C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\lib\waterline\core\validations.js:188:31
    at C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\async\lib\async.js:52:16
    at Object.async.forEachOf.async.eachOf (C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\async\lib\async.js:236:30)
    at Object.async.forEach.async.each (C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\async\lib\async.js:209:22)
    at validate (C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\lib\waterline\core\validations.js:163:11)
    at C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\async\lib\async.js:181:20
    at Object.async.forEachOf.async.eachOf (C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\async\lib\async.js:233:13)
    at Object.async.forEach.async.each (C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\async\lib\async.js:209:22)
    at Validator.validate (C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\lib\waterline\core\validations.js:207:9)
    at C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\lib\waterline\query\validate.js:42:25
    at C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\async\lib\async.js:718:13
    at Immediate.iterate [as _onImmediate] (C:\Users\jpbecotte\Documents\prog\autoparts-backend\node_modules\sails\node_modules\waterline\node_modules\async\lib\async.js:262:13)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

In the doc, , it says:

"Ensure incoming value matches the configured regular expression."

@sailsbot
Copy link

Hi @jpbecotte! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected].

@jpbecotte
Copy link
Author

Ok, fixed!

@mikermcneil
Copy link
Member

Hey @jpbecotte, thank you for the report. One of us will look into this asap. In the mean time, just flagged this issue as a bug, and for reference, here's the link to the is validation rule in our documentation: http://sailsjs.org/documentation/concepts/models-and-orm/validations (btw- on a separate note, that doc page could use some more work. I took a pass at improving the validation docs about a month ago, so they're somewhat better now, but if anyone reading this notices any out-of-date info, please don't hesitate to scroll down to the bottom and edit the page)

Thanks again!

@mikermcneil mikermcneil changed the title Model validation "is" not working is model validation rule missing in v0.12.1 (Error: Unknown rule: is) Mar 10, 2016
@mikermcneil mikermcneil added the orm Related to models, datastores, orm config, Waterline, sails-hook-orm, etc. label Mar 10, 2016
@mikermcneil
Copy link
Member

@jpbecotte just recreated this and tracked it down to sailshq/anchor@e7fbec2#diff-b9cfc7f2cdf78a7f4b91a753d10865a2 which seems to be the culprit.

@mikermcneil
Copy link
Member

@jpbecotte in the middle of working this out and will have a fix in shortly. First and foremost, while it's not a huge deal in this case, Waterline should crash the process in this case, so I'm starting there.

@mikermcneil
Copy link
Member

forgot to ref from the other side, so balderdashy/waterline@935f4a0

@mikermcneil
Copy link
Member

@jpbecotte ok! This is solved by anchor 0.11.1, which should be picked up automatically if you reinstall sails and its deps (if you have trouble, try npm cache clear && rm -rf node_modules && npm install --force).

(Also, the next release of Waterline will handle unrecognized validation rule errors more gracefully.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug orm Related to models, datastores, orm config, Waterline, sails-hook-orm, etc.
Development

No branches or pull requests

3 participants