Changeset 9094
- Timestamp:
- 03/26/08 15:26:59 (3 months ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/association_preload.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r9093 r9094 1 1 *SVN* 2 3 * More efficient association preloading code that compacts a through_records array in a central location. Closes #11427 [danger] 2 4 3 5 * Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert] trunk/activerecord/lib/active_record/association_preload.rb
r9075 r9094 116 116 source = reflection.source_reflection.name 117 117 through_records.first.class.preload_associations(through_records, source) 118 through_records. compact.each do |through_record|118 through_records.each do |through_record| 119 119 add_preloaded_record_to_collection(id_to_record_map[through_record[through_primary_key].to_i], 120 120 reflection.name, through_record.send(source)) 121 121 end 122 end 123 else 122 end 123 else 124 124 records.each {|record| record.send("set_#{reflection.name}_target", nil)} 125 125 126 126 127 127 set_association_single_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options), reflection.primary_key_name) 128 end 128 end 129 129 end 130 130 … … 141 141 source = reflection.source_reflection.name 142 142 through_records.first.class.preload_associations(through_records, source) 143 through_records. compact.each do |through_record|143 through_records.each do |through_record| 144 144 add_preloaded_records_to_collection(id_to_record_map[through_record[through_primary_key].to_i], 145 145 reflection.name, through_record.send(source)) … … 160 160 preload_options = {:conditions => ["#{interface} = ?", reflection.options[:source_type]]} 161 161 162 records.compact! 162 163 records.first.class.preload_associations(records, through_association, preload_options) 163 164 164 165 # Dont cache the association - we would only be caching a subset 165 166 through_records = [] 166 records. compact.each do |record|167 records.each do |record| 167 168 proxy = record.send(through_association) 168 169 … … 174 175 end 175 176 end 176 through_records = through_records.flatten177 through_records.flatten! 177 178 else 178 179 records.first.class.preload_associations(records, through_association) 179 through_records = records.compact.map {|record| record.send(through_association)}.flatten 180 end 180 through_records = records.map {|record| record.send(through_association)}.flatten 181 end 182 through_records.compact! 183 through_records 181 184 end 182 185