aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorTarmo Tänav <tarmo@itech.ee>2009-06-10 16:24:32 +0300
committerSantiago Pastorino <santiago@wyeworks.com>2010-07-29 22:37:20 -0300
commit2ea922bcec333b6484a295b4fee1f4fa75c5704d (patch)
treed8505adef8028de6cd78d20038d36bea3715257c /activerecord/lib
parentccd45618ed9a629c9535a5ff84ef5c238befa4ab (diff)
downloadrails-2ea922bcec333b6484a295b4fee1f4fa75c5704d.tar.gz
rails-2ea922bcec333b6484a295b4fee1f4fa75c5704d.tar.bz2
rails-2ea922bcec333b6484a295b4fee1f4fa75c5704d.zip
Don't increment and then decrement the same counter when re-assigning a belongs_to association
[#2786 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_association.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index c2a6495db5..4558872a2b 100644
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -22,7 +22,7 @@ module ActiveRecord
else
raise_on_type_mismatch(record)
- if counter_cache_name && !@owner.new_record?
+ if counter_cache_name && !@owner.new_record? && record.id != @owner[@reflection.primary_key_name]
@reflection.klass.increment_counter(counter_cache_name, record.id)
@reflection.klass.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name]
end