diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-07-18 10:28:24 -0400 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-07-18 10:30:58 -0400 |
commit | 7550f0a016ee6647aaa76c0c0ae30bebc3867288 (patch) | |
tree | 1a13b0e841e8e2aac71abed0d3192d25b408ac65 /activerecord/lib | |
parent | 2a0a264b39eb99ddf444bbdacf3014868c8896cc (diff) | |
download | rails-7550f0a016ee6647aaa76c0c0ae30bebc3867288.tar.gz rails-7550f0a016ee6647aaa76c0c0ae30bebc3867288.tar.bz2 rails-7550f0a016ee6647aaa76c0c0ae30bebc3867288.zip |
Ensure cyclic associations w/ autosave don't cause duplicate errors
This code is so fucked. Things that cause this bug not to replicate:
- Defining the validation before the association (we end up calling
`uniq!` on the errors in the autosave validation)
- Adding `accepts_nested_attributes_for` (I have no clue why. The only
thing it does that should affect this is adds `autosave: true` to the
inverse reflection, and doing that manually doesn't fix this).
This solution is a hack, and I'm almost certain there's a better way to
go about it, but this shouldn't cause a huge hit on validation times,
and is the simplest way to get it done.
Fixes #20874.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 0792d19c3e..5f38bd51f6 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -222,6 +222,7 @@ module ActiveRecord true end validate validation_method + after_validation :_ensure_no_duplicate_errors end end end @@ -456,5 +457,11 @@ module ActiveRecord end end end + + def _ensure_no_duplicate_errors + errors.messages.each_key do |attribute| + errors[attribute].uniq! + end + end end end |