aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/CHANGELOG.md
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2013-03-15 19:25:31 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2013-03-15 19:25:31 -0700
commit34be80443c76dde393ae5e2b28805bd01605eadc (patch)
tree81cd0e44ec560b673938f78135c9b72bbd667183 /activerecord/CHANGELOG.md
parentae8e84e976c296596adf97f60932bd3a164506b4 (diff)
parent455d710242f24f0cfff89f626164493276e0f3e9 (diff)
downloadrails-34be80443c76dde393ae5e2b28805bd01605eadc.tar.gz
rails-34be80443c76dde393ae5e2b28805bd01605eadc.tar.bz2
rails-34be80443c76dde393ae5e2b28805bd01605eadc.zip
Merge pull request #9737 from wangjohn/counter_cache_update_attributes_fix
The counter cache will now work correctly when the foreign key is changed. Fixes #9722.
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r--activerecord/CHANGELOG.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index a8151cd23e..79ca34d89d 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,31 @@
## Rails 4.0.0 (unreleased) ##
+* Counter caches on associations will now stay valid when attributes are
+ updated (not just when records are created or destroyed), for example,
+ when calling +update_attributes+. The following code now works:
+
+ class Comment < ActiveRecord::Base
+ belongs_to :post, counter_cache: true
+ end
+
+ class Post < ActiveRecord::Base
+ has_many :comments
+ end
+
+ post = Post.create
+ comment = Comment.create
+
+ post.comments << comment
+ post.save.reload.comments_count # => 1
+ comment.update_attributes(:post_id => nil)
+
+ post.save.reload.comments_count # => 0
+
+ Updating the id of a +belongs_to+ object with the id of a new object will
+ also keep the count accurate.
+
+ *John Wang*
+
* Referencing join tables implicitly was deprecated. There is a
possibility that these deprecation warnings are shown even if you
don't make use of that feature. You can now disable the feature entirely.