mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fixed postgresql limited eager loading for the case where scoped :order was present
This commit is contained in:
committed by
Jeremy Kemper
parent
3451045658
commit
8c91b767c0
@@ -1486,10 +1486,15 @@ module ActiveRecord
|
||||
join_dependency.joins_for_table_name(table)
|
||||
}.flatten.compact.uniq
|
||||
|
||||
order = options[:order]
|
||||
if scoped_order = (scope && scope[:order])
|
||||
order = order ? "#{order}, #{scoped_order}" : scoped_order
|
||||
end
|
||||
|
||||
is_distinct = !options[:joins].blank? || include_eager_conditions?(options, tables_from_conditions) || include_eager_order?(options, tables_from_order)
|
||||
sql = "SELECT "
|
||||
if is_distinct
|
||||
sql << connection.distinct("#{connection.quote_table_name table_name}.#{primary_key}", options[:order])
|
||||
sql << connection.distinct("#{connection.quote_table_name table_name}.#{primary_key}", order)
|
||||
else
|
||||
sql << primary_key
|
||||
end
|
||||
@@ -1503,8 +1508,8 @@ module ActiveRecord
|
||||
add_conditions!(sql, options[:conditions], scope)
|
||||
add_group!(sql, options[:group], scope)
|
||||
|
||||
if options[:order] && is_distinct
|
||||
connection.add_order_by_for_association_limiting!(sql, options)
|
||||
if order && is_distinct
|
||||
connection.add_order_by_for_association_limiting!(sql, :order => order)
|
||||
else
|
||||
add_order!(sql, options[:order], scope)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user