diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-09-19 01:11:07 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-09-19 01:11:07 +0900 |
commit | afea273960e286712c86c272015a6a4767677992 (patch) | |
tree | 8e88ed8d5aa37faa68d3afd0469d8f862d12ba41 /activerecord/test/cases/associations/belongs_to_associations_test.rb | |
parent | e925cb4d856088a815bf4a0cf27518d01bb4029d (diff) | |
download | rails-afea273960e286712c86c272015a6a4767677992.tar.gz rails-afea273960e286712c86c272015a6a4767677992.tar.bz2 rails-afea273960e286712c86c272015a6a4767677992.zip |
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.
Diffstat (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 1 |
1 files changed, 1 insertions, 0 deletions
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 |