This project is archived and is in readonly mode.
counter_cache not updating on update_attributes
Reported by Elad Meidar | February 9th, 2010 @ 04:56 AM
When trying to use a simple case of
cache_counter
:
class Registration < ActiveRecord::Base
belongs_to :section, :counter_cache => :registrations_count
end
class Section < ActiveRecord::Base
has_many :registrations
end
and i wanted to test the scenario where i change the section id on a registration record, if the old one's counter cache will -1 and the new one will +1.
here's the test:
def test_registration_update_changes_section_counts_when_update_attributes
sec1 = Section.create! :name => "foo"
sec2 = Section.create! :name => "bar"
r = Registration.create! :name => "foo", :section => sec1
sec1.reload
puts "Section 1 registrations: " + sec1.registrations_count.to_s
assert_equal 1, sec1.registrations_count
r.update_attributes(:section_id => sec2)
sec1.reload
puts "Section 1 after reduce: " + sec1.reload.registrations_count.to_s
assert_equal 0, sec1.registrations_count
sec2.reload
assert_equal 1, sec2.registrations_count
end
which fails.
The patch applies on 2-3-stable (pulled today) but i am uncertain it's the right way to solve it. i'll wait for the discussion here and create a master patch based on comments.
Comments and changes to this ticket
-
Ryan Bigg October 11th, 2010 @ 01:02 AM
- State changed from new to open
- Importance changed from to Low
Hey Elad,
Is this now fixed in 2-3-stable? Could you please update this ticket with your findings? Thanks.
(yay for delegation)
-
rails February 26th, 2011 @ 12:00 AM
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails February 26th, 2011 @ 12:00 AM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>