提交 9a421aaa 编写于 作者: X Xavier Noria

fixes markup of the CHANGELOG entry from 455d7102

上级 34be8044
......@@ -2,26 +2,26 @@
* 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:
when calling `update_attributes`. The following code now works:
class Comment < ActiveRecord::Base
belongs_to :post, counter_cache: true
end
class Comment < ActiveRecord::Base
belongs_to :post, counter_cache: true
end
class Post < ActiveRecord::Base
has_many :comments
end
class Post < ActiveRecord::Base
has_many :comments
end
post = Post.create
comment = Comment.create
post = Post.create
comment = Comment.create
post.comments << comment
post.save.reload.comments_count # => 1
comment.update_attributes(:post_id => nil)
post.comments << comment
post.save.reload.comments_count # => 1
comment.update_attributes(post_id: nil)
post.save.reload.comments_count # => 0
post.save.reload.comments_count # => 0
Updating the id of a +belongs_to+ object with the id of a new object will
Updating the id of a `belongs_to` object with the id of a new object will
also keep the count accurate.
*John Wang*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册