From afea273960e286712c86c272015a6a4767677992 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Wed, 19 Sep 2018 01:11:07 +0900 Subject: Avoid the same `foreign_key` and `counter_cache` associations on `SillyReply` `topic` and `reply` belongs_to associations on `SillyReply` are defined with the same `foreign_key` (`parent_id`) and `counter_cache` (`replies_count`) columns. This would cause unintentional side-effect (e.g. saving `SillyReply` object would cause double increment `replies_count`), so it is better to avoid that side-effect. --- activerecord/test/cases/associations/belongs_to_associations_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 0cc4ed7127..169ff96b94 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -827,6 +827,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase silly = SillyReply.create(title: "gaga", content: "boo-boo") silly.reply = reply + silly.save! assert_equal 1, reply.reload[:replies_count] assert_equal 1, reply.replies.size -- cgit v1.2.3