From bb17c3b2105da30ef3260c3b489da85e4865eaa5 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Tue, 31 Dec 2013 02:44:27 +0530 Subject: https://github.com/rails/rails/commit/2075f39d726cef361170218fd16421fc52bed5a8 introduced a regression in includes/preloades by calling `read_attribute` on an association when preloading takes places, instead of using loaded records in `association.target`. tl;dr Records are not made properly available via `read_attribute` when preloding in simultaneous, but value of `@loaded` is already set true, and records concatenated in `association.target` on an association object. When `@loaded` is true we return an object of `AlreadyLoaded` in preload_for. In `AlreadyLoaded` to return preloaded records we make wrong use of `read_attribute`, instead of `target` records. The regression is fixed by making use of the loaded records in `association.target` when the preloading takes place. Fixes #13437 --- activerecord/lib/active_record/associations/preloader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 2393667ac8..83637a0409 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -183,7 +183,7 @@ module ActiveRecord def run(preloader); end def preloaded_records - owners.flat_map { |owner| owner.read_attribute reflection.name } + owners.flat_map { |owner| owner.association(reflection.name).target } end end -- cgit v1.2.3