From 5f9e05048d409b9c3fb35a3620fe361fb03dd4e1 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 9 Feb 2019 00:46:18 +0900 Subject: Refactor to just use `Association#target=` in `associate_records_to_owner` `Association#target=` invokes `loaded!`, so we no longer need to call the `loaded!` explicitly. Since Preloader is private API, we don't guarantee that it behaves like older version as long as using Preloader directly. But this refactoring fortunately also fix the Preloader compatibility issue #35195. Closes #35195. --- activerecord/lib/active_record/associations/preloader/association.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index d6f7359055..041e62077c 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -42,11 +42,10 @@ module ActiveRecord def associate_records_to_owner(owner, records) association = owner.association(reflection.name) - association.loaded! if reflection.collection? - association.target.concat(records) + association.target = records else - association.target = records.first unless records.empty? + association.target = records.first end end -- cgit v1.2.3