aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-02-09 00:46:18 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-02-09 01:04:59 +0900
commit5f9e05048d409b9c3fb35a3620fe361fb03dd4e1 (patch)
tree88de37f3854e3f3f03165dc62eae475377cda2f9 /activerecord
parent216b8aa40f694fddb51c22f5dfc150f6ca578598 (diff)
downloadrails-5f9e05048d409b9c3fb35a3620fe361fb03dd4e1.tar.gz
rails-5f9e05048d409b9c3fb35a3620fe361fb03dd4e1.tar.bz2
rails-5f9e05048d409b9c3fb35a3620fe361fb03dd4e1.zip
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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/preloader/association.rb5
1 files changed, 2 insertions, 3 deletions
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