On Friday, June 5, 2015 at 2:46:54 PM UTC-7, 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.
>

This behavior is by design:

o = Order.last
o.valid? #=> false
o.errors # => {"name"=>"is not present"}
o.name = 'Foo'
o.valid? # => true

If you really want to make sure a model will be considered invalid when 
saved, use the instance_hooks plugin:

Order.plugin :instance_hooks
o = Order.last
o.before_validation_hook{o.errors.add(nil, 'Test')}
o.valid?  # => false

Thanks,
Jeremy

-- 
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.

Reply via email to