Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8896

Show
Ignore:
Timestamp:
02/19/08 02:56:05 (8 months ago)
Author:
bitsweat
Message:

Don't assume all records from nested include are of same class. Closes #11154 [acechase]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/association_preload.rb

    r8894 r8896  
    3535        raise ConfigurationError, "Association named '#{ association }' was not found; perhaps you misspelled it?" unless reflection 
    3636 
    37         send(:"preload_#{reflection.macro}_association", records, reflection, preload_options) 
     37        # Not all records have the same class, so group then preload. 
     38        records.group_by(&:class).each do |klass, records| 
     39          reflection = klass.reflections[association] 
     40          send("preload_#{reflection.macro}_association", records, reflection, preload_options) 
     41        end 
    3842      end 
    3943