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

Ticket #3438: eager_loading_order_fix.diff

File eager_loading_order_fix.diff, 1.2 kB (added by coda.hale@gmail.com, 4 years ago)

A fix for this, no unit tests, relatively untested

  • activerecord/lib/active_record/associations.rb

    old new  
    11481148          add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit]) 
    11491149 
    11501150          sql << "ORDER BY #{options[:order]} " if options[:order] 
     1151 
     1152          if options[:include] 
     1153            ordered_reflections = [] 
     1154            for association, reflection in reflections 
     1155              ordered_reflections << reflection if options[:include].include?(association) && reflection.options[:order] 
     1156            end 
     1157            if ordered_reflections.any? 
     1158              if options[:order] 
     1159                sql << ", " 
     1160              else 
     1161                sql << "ORDER BY " 
     1162              end 
     1163              sql << "#{ordered_reflections.map{ |r| r.options[:order] }.join(', ')} " if ordered_reflections.any? 
     1164            end 
     1165          end 
    11511166  
    11521167          add_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections) 
    11531168