aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-02-19 02:56:05 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-02-19 02:56:05 +0000
commit331d9c04917b19fb8b73d564eae0576b60e1ed38 (patch)
tree888937e1e97c8cfb6d93392aba239b5499855d05 /activerecord/lib
parent21c75e545a798b75d3ad1eaceea567e725ee655a (diff)
downloadrails-331d9c04917b19fb8b73d564eae0576b60e1ed38.tar.gz
rails-331d9c04917b19fb8b73d564eae0576b60e1ed38.tar.bz2
rails-331d9c04917b19fb8b73d564eae0576b60e1ed38.zip
Don't assume all records from nested include are of same class. Closes #11154 [acechase]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8896 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/association_preload.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index 9ef8ed15e8..313c51dae0 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -34,7 +34,11 @@ module ActiveRecord
reflection = reflections[association]
raise ConfigurationError, "Association named '#{ association }' was not found; perhaps you misspelled it?" unless reflection
- send(:"preload_#{reflection.macro}_association", records, reflection, preload_options)
+ # Not all records have the same class, so group then preload.
+ records.group_by(&:class).each do |klass, records|
+ reflection = klass.reflections[association]
+ send("preload_#{reflection.macro}_association", records, reflection, preload_options)
+ end
end
def add_preloaded_records_to_collection(parent_records, reflection_name, associated_record)