Changeset 8051
- Timestamp:
- 10/29/07 03:02:42 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r8049 r8051 1 1 *SVN* 2 3 * Associations: speedup duplicate record check. #10011 [lifofifo] 2 4 3 5 * Make sure that << works on has_many associations on unsaved records. Closes #9989 [hasmanyjosh] trunk/activerecord/lib/active_record/associations.rb
r8046 r8051 1403 1403 construct(@base_records_hash[primary_id], @associations, join_associations.dup, row) 1404 1404 end 1405 remove_duplicate_results!(join_base.active_record, @base_records_in_order, @associations) 1405 1406 return @base_records_in_order 1407 end 1408 1409 def remove_duplicate_results!(base, records, associations) 1410 case associations 1411 when Symbol, String 1412 reflection = base.reflections[associations] 1413 if reflection && [:has_many, :has_and_belongs_to_many].include?(reflection.macro) 1414 records.each { |record| record.send(reflection.name).target.uniq! } 1415 end 1416 when Array 1417 associations.each do |association| 1418 remove_duplicate_results!(base, records, association) 1419 end 1420 when Hash 1421 associations.keys.each do |name| 1422 reflection = base.reflections[name] 1423 is_collection = [:has_many, :has_and_belongs_to_many].include?(reflection.macro) 1424 1425 parent_records = records.map do |record| 1426 next unless record.send(reflection.name) 1427 is_collection ? record.send(reflection.name).target.uniq! : record.send(reflection.name) 1428 end.flatten.compact 1429 1430 remove_duplicate_results!(reflection.class_name.constantize, parent_records, associations[name]) unless parent_records.empty? 1431 end 1432 end 1406 1433 end 1407 1434 … … 1462 1489 return nil if record.id.to_s != join.parent.record_id(row).to_s or row[join.aliased_primary_key].nil? 1463 1490 association = join.instantiate(row) 1464 collection.target.push(association) unless collection.target.include?(association)1491 collection.target.push(association) 1465 1492 when :has_one 1466 1493 return if record.id.to_s != join.parent.record_id(row).to_s