    # File lib/active_record/connection_adapters/postgresql_adapter.rb, line 408
          def add_order_by_for_association_limiting!(sql, options)
            return sql if options[:order].blank?

            order = options[:order].split(',').collect { |s| s.strip }.reject(&:blank?)
            order.map! { |s| 'DESC' if s =~ /\bdesc$/i }
            order = order.zip((0...order.size).to_a).map { |s,i| "id_list.alias_#{i} #{s}" }.join(', ')

            sql.replace "SELECT * FROM (#{sql}) AS id_list ORDER BY #{order}"
          end