From 3417547111c176303c6f270591e6da167c128495 Mon Sep 17 00:00:00 2001 From: Andrew Chase Date: Wed, 10 Dec 2008 13:32:49 -0800 Subject: [PATCH] Fixing a problem with eager loading polymporphic associations --- .../lib/active_record/association_preload.rb | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index 99c3ce5..7de0122 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -117,7 +117,9 @@ module ActiveRecord # 'reflection.macro' can return 'belongs_to', 'has_many', etc. Thus, # the following could call 'preload_belongs_to_association', # 'preload_has_many_association', etc. - send("preload_#{reflection.macro}_association", records, reflection, preload_options) + # We want to call preload_XXX_association on the class we've grouped on, + # not the class we're currently in. Use the record class, not the current class. + records.first.class.send("preload_#{reflection.macro}_association", records, reflection, preload_options) end end -- 1.6.0.2