If I remember correctly, adding an error to an AR object''s attribute or :base previously prevented the object from being saved. This is not the current behavior of Active Record. user = User.last user.errors.add :name, "name doesn''t rhyme with orange" user.valid? # => true user.save # => true user = User.last user.errors.add :base, "my unique error" user.valid? # => true user.save # => true Is that an intentional change, or an accidental one? Would a patch preventing objects with errors from saving be considered? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
On Wednesday, 14 March 2012 at 11:13 AM, richard schneeman wrote:> Is that an intentional change, or an accidental one? Would a patch > preventing objects with errors from saving be considered? >valid? resets the state of errors, this has been the case for years: https://github.com/rails/rails/blob/2-3-stable/activerecord/lib/active_record/validations.rb#L1107 You can only add to errors during the validation callbacks if you want to prevent the save from happening -- Cheers, Koz -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.