This project is archived and is in readonly mode.
Custom counter caches not being used
-
Pratik
- Assigned user set to Pratik
- Tag set to activerecord, patch
- State changed from new to incomplete
I think the key needs to be named differently, probably :counter_cache_attribute or something. Also, the tests shouldn't really use mocking/stubbing.
Thanks.
-
CancelProfileIsBroken
- Tag changed from activerecord, patch to activerecord, bugmash, patch
-
Derander
-1, this is fixed in 2-3-stable and master.
-
Derander
To verify the fix,
rails test2
cd test2
script/generate model Post title:string custom_count:integer
script/generate model Comment title:string post_id:integer
In post.rb: has_many :comments
in comment.rb: belongs_to :post, :counter_cache => :custom_count
./script/console
p = Post.create(:title => "A Post")
p.comments.build(:title => "A comment")
p.save
p.custom_count should be 1
-
CancelProfileIsBroken
- Tag changed from activerecord, bugmash, patch to activerecord, patch
- State changed from incomplete to resolved
-
Derander
- Tag changed from activerecord, patch to activerecord, patch
Jose Valim found an error in my understanding of the patch.
The problem is not found by examining the value of p.custom_count, instead, starting from p.save:
p.custom_count = 10
p.save
p.comments.count will be 1. #It should be 10 if custom_count were being used.
-
José Valim
- State changed from resolved to new
Since we added :inverse_of in master (Rails 3.0), we could make use of it to retrieve the counter cache column, instead of adding a new option to has_many which may be confusing.
-
Ryan Bigg
Automatic cleanup of spam.
-
Jeff Kreeftmeijer
Automatic cleanup of spam.
-
Jeff Kreeftmeijer
Automatic cleanup of spam.
-
Aditya Sanghi
- Title changed from Add magic encoding comment to generated files to Custom counter caches not being used
