-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Validations #4
base: master
Are you sure you want to change the base?
Validations #4
Conversation
Hey @atlantis, thanks for the PR this is a great addition ❤️ !
Nice, and if users want to add validation with the regular insert/update methods they can use hooks (
I think we can work around that by dropping the I would also like to make I have made some changes based on what I wrote above on a separate branch (I don't know if there is better way to contribute to an external PR, maybe this?) If you are cool with the changes then we'll also need to document everything properly at some point 😉. |
make validation optional and allow inheritance
Great! Looks like there's a conflict so I may let you resolve that if that's OK to make sure the correct parts get kept... |
And I'll work on documentation in the next few days - do you want it on the main Readme or just documented in the API docs? |
Sure, I'll look into it!
I you could handle the API docs it would be great, and as a follow up I'll add a paragraph in the readme. |
First shot at validations - it's a bit more complex than ActiveRecord because I've always wanted the ability to have the backend generate warnings that don't prevent the model saving but can be displayed to the user/cause some other action.
validate :field, :present
validate :field, "must be capitalized" { |model| ... true|false|nil }
validate :field {|model, problems| ... problems << MySpecialError.new("Stuff") ... }
save
method that only inserts/updates upon successful validation -insert
andupdate
behavior are unaffected.One side-effect of the way I wrote this is that you can't have a model class inherit from another non-abstract model class... that seems lame but I couldn't figure out a way around it so far 🤷