aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorlulalala <mark@goodlife.tw>2018-04-03 13:06:04 +0800
committerlulalala <mark@goodlife.tw>2019-03-31 22:59:12 +0800
commit86620cc3aa8e2630bc8d934b1a86453276b9eee9 (patch)
treef9853d8b8b55469c8e0a9facca31c647337c23ea /activemodel/lib
parent2a06f13099b3344e93198728795209bc69501d4a (diff)
downloadrails-86620cc3aa8e2630bc8d934b1a86453276b9eee9.tar.gz
rails-86620cc3aa8e2630bc8d934b1a86453276b9eee9.tar.bz2
rails-86620cc3aa8e2630bc8d934b1a86453276b9eee9.zip
Allow errors to remove duplicates, and ensure cyclic associations w/ autosave duplicate errors can be removed
See SHA 7550f0a016ee6647aaa76c0c0ae30bebc3867288
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/error.rb15
-rw-r--r--activemodel/lib/active_model/errors.rb2
2 files changed, 16 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/error.rb b/activemodel/lib/active_model/error.rb
index b1912f2604..9731fa74df 100644
--- a/activemodel/lib/active_model/error.rb
+++ b/activemodel/lib/active_model/error.rb
@@ -62,5 +62,20 @@ module ActiveModel
full_message == Error.new(@base, attribute, type, **options).full_message
end
+
+ def ==(other)
+ attributes_for_hash == other.attributes_for_hash
+ end
+ alias eql? ==
+
+ def hash
+ attributes_for_hash.hash
+ end
+
+ protected
+
+ def attributes_for_hash
+ [@base, @attribute, @raw_type, @options]
+ end
end
end
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index bb64bc6264..2d559e06d4 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -64,7 +64,7 @@ module ActiveModel
include Enumerable
extend Forwardable
- def_delegators :@errors, :size, :clear, :blank?, :empty?
+ def_delegators :@errors, :size, :clear, :blank?, :empty?, :uniq!
# TODO: forward all enumerable methods after `each` deprecation is removed.
def_delegators :@errors, :count