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, :presentvalidate :field, "must be capitalized" { |model| ... true|false|nil }validate :field {|model, problems| ... problems << MySpecialError.new("Stuff") ... }savemethod that only inserts/updates upon successful validation -insertandupdatebehavior 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 🤷