0
@@ -10,6 +10,8 @@ module ActiveRecord
0
# preload_options is passed only one level deep: don't pass to the child associations when associations is a Hash
0
def preload_associations(records, associations, preload_options={})
0
+ logger.debug("!!!!!!!!!!!!!!!!!!!! ACC preload_associations in class #{self.name}")
0
+ logger.debug("associations: #{associations.inspect}")
0
records = [records].flatten.compact.uniq
0
return if records.empty?
0
@@ -22,7 +24,10 @@ module ActiveRecord
0
reflection = reflections[parent]
0
parents = records.map {|record| record.send(reflection.name)}.flatten
0
unless parents.empty? || parents.first.nil?
0
- parents.first.class.preload_associations(parents, child)
0
+ class_to_reflection = {}
0
+ parents.group_by(&:class).each do |parent_class, grouped_parents|
0
+ parent_class.preload_associations(grouped_parents,child)
0
@@ -36,7 +41,7 @@ module ActiveRecord
0
# group on the reflection itself so that if various subclass share the same association then we do not split them
0
records.group_by {|record| class_to_reflection[record.class] ||= record.class.reflections[association]}.each do |reflection, records|
0
- raise ConfigurationError, "Association named
'#{ association }' was not found; perhaps you misspelled it?" unless reflection
0
+ raise ConfigurationError, "Association named
\'#{ association }\' was not found; perhaps you misspelled it?" unless reflection
0
send("preload_#{reflection.macro}_association", records, reflection, preload_options)
0
@@ -58,6 +63,7 @@ module ActiveRecord
0
def set_association_collection_records(id_to_record_map, reflection_name, associated_records, key)
0
+ logger.debug("!!!!!!!!!!!!!!!!!!!! ACC set_association_collection_records #{reflection_name} #{key}")
0
associated_records.each do |associated_record|
0
mapped_records = id_to_record_map[associated_record[key].to_s]
0
add_preloaded_records_to_collection(mapped_records, reflection_name, associated_record)
0
@@ -181,6 +187,7 @@ module ActiveRecord
0
through_records.flatten!
0
+ logger.debug("!!!!!!!!!!!!!!!!!!!! ACC preload_associations using #{records.first.class.name}")
0
records.first.class.preload_associations(records, through_association)
0
through_records = records.map {|record| record.send(through_association)}.flatten
0
@@ -239,11 +246,14 @@ module ActiveRecord
0
def find_associated_records(ids, reflection, preload_options)
0
+ logger.debug("!!!!!!!!!!!!!!!!!!!! ACC find_associated_records #{reflection.inspect}\n#{preload_options.inspect}")
0
options = reflection.options
0
table_name = reflection.klass.quoted_table_name
0
if interface = reflection.options[:as]
0
+ # interface_class = reflection.active_record
0
conditions = "#{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_id"} IN (?) and #{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_type"} = '#{self.base_class.name.demodulize}'"
0
+ # conditions = "#{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_id"} IN (?) and #{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_type"} = '#{interface_class.name.demodulize}'"
0
foreign_key = reflection.primary_key_name
0
conditions = "#{reflection.klass.quoted_table_name}.#{foreign_key} IN (?)"