aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/CHANGELOG.md
diff options
context:
space:
mode:
authorJohn Wang <john@panjiva.com>2013-03-15 11:48:53 -0400
committerwangjohn <wangjohn@mit.edu>2013-03-15 21:28:28 -0400
commit455d710242f24f0cfff89f626164493276e0f3e9 (patch)
tree81cd0e44ec560b673938f78135c9b72bbd667183 /activerecord/CHANGELOG.md
parentae8e84e976c296596adf97f60932bd3a164506b4 (diff)
downloadrails-455d710242f24f0cfff89f626164493276e0f3e9.tar.gz
rails-455d710242f24f0cfff89f626164493276e0f3e9.tar.bz2
rails-455d710242f24f0cfff89f626164493276e0f3e9.zip
If a counter_cache is defined, then using update_attributes and changing
the primary key on an association will make sure that the corresponding counter on the association is changed properly. 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.