From de32d972bfde8871f7c1a4621f2223ea9b6715b2 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sun, 30 Mar 2014 20:23:50 +0200 Subject: Fix polymorphic preloads on NOT NULL _type columns. Defer to Association#klass instead of having a custom/duplicate code. --- activerecord/lib/active_record/associations/preloader.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 83637a0409..e6485b2b0c 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -144,7 +144,7 @@ module ActiveRecord reflection_records.each_with_object({}) do |(reflection, r_records),h| h[reflection] = r_records.group_by { |record| - association_klass(reflection, record) + record.association(association).klass } end end @@ -163,15 +163,6 @@ module ActiveRecord "perhaps you misspelled it?" end - def association_klass(reflection, record) - if reflection.macro == :belongs_to && reflection.options[:polymorphic] - klass = record.read_attribute(reflection.foreign_type.to_s) - klass && klass.constantize - else - reflection.klass - end - end - class AlreadyLoaded attr_reader :owners, :reflection -- cgit v1.2.3