I wanted to do validations outside of the model (so outside of
`Sequel::Model#validate`), and then I also found out that #valid? first
clears the errors. For me it worked that instead of `#valid?` I just used
`errors.empty?`, and it worked great for my case.
If you do want to have validations in your model, and you don't have any
*_validation hooks, you could override #valid? to suit your needs:
class Sequel::Model
def valid?
validate
errors.empty?
end
end
What's great about Sequel that unlike ActiveRecord it uses instance
methods, and it's very clear what they do, so it's very easy to peek at the
source code and override things.
On Friday, June 5, 2015 at 11:46:54 PM UTC+2, James wrote:
>
> This is sort of a feature request I guess, and something that's caused me
> to bang my head a few times now. Currently you can access #errors and
> #errors.add methods on a model, but they're not of any use (that I'm aware
> of). Any errors added using errors.add() prior to calling valid? will be
> discarded when you call valid?. It would be much more intuitive to be able
> to add errors to a model prior to calling valid?, and have them cause
> valid? to return false.
>
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.