From 0255cf94b0871230aba106543c17918caafbef0e Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 26 Jun 2018 05:46:09 +0900 Subject: Don't share seen object cache between different join nodes in eager loading Currently, the seen object cache is shared if join nodes have the same target class. But it is a wrong assumption, we can't share the seen object cache between different join nodes (e.g. `:readonly_account` and `:accounts` have the same target class `Account`, but the instances have the different state `readonly`). Fixes #26805. Closes #27737. --- activerecord/lib/active_record/associations/join_dependency.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 8cf1b5d25a..be56d27021 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -225,7 +225,7 @@ module ActiveRecord next end - model = seen[ar_parent.object_id][node.base_klass][id] + model = seen[ar_parent.object_id][node][id] if model construct(model, node, row, seen, model_cache) @@ -237,7 +237,7 @@ module ActiveRecord model.readonly! end - seen[ar_parent.object_id][node.base_klass][id] = model + seen[ar_parent.object_id][node][id] = model construct(model, node, row, seen, model_cache) end end -- cgit v1.2.3