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
Field validation occurs _before_ beforeCreate()
#6890
Comments
@alxndrsn Thanks for posting! We'll take a look as soon as possible. In the mean time, there are a few ways you can help speed things along:
Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly. For help with questions about Sails, click here. |
beforeCreate()
@alxndrsn Thanks for bringing this up as well. Also not entirely sure if this was intentional or just a bug - will have to team examine the logic behind this one as well. |
Thanks, I look forward to hearing more 🙂 |
@alxndrsn this is intentional, but it'd definitely be a good idea to update the docs clarifying when these things run. |
@rachaelshaw With reference to helpers, this seems to an entirely different mechanism to the lifecycle callbacks queried in this issue, which are designed to capture all operations, both Waterline Model operations and blueprints. @alxndrsn I've facing a similar issue. If blueprints are what you are targeting, I've been looking at intercepting the process in |
@danielsharvey not using blueprints, but thanks for sharing your approach - hopefully helpful to others. @rachaelshaw I guess I could use helpers 🤷♂️ My specific use case is using uuids instead of autoincremented numbers for database IDs, and it makes for a lot of noise in my code. I don't think this could be solved with I note that
|
@alxndrsn Understood. I am also using |
Hey, @alxndrsn! Thanks for drawing our attention to that misleading error message; I've gone ahead and updated it. |
Node version: 10
Sails version (sails): 1.2.3
It seems that field validation when calling
SomeModel.create()
is done before thebeforeCreate()
lifecycle callback.This seems surprising, as it means that e.g.
beforeCreate()
, and alsonumber
field if set in beforeCreate() callback #6889, values set inbeforeCreate()
skip the sails type-based validationIs this the intended behaviour? If so, I think it would be helpful to document it on https://sailsjs.com/documentation/concepts/models-and-orm/lifecycle-callbacks; if not, would a PR to move validation to after the
beforeCreate()
callback be considered?The text was updated successfully, but these errors were encountered: