Permalink
Browse files

Fixed postgresql limited eager loading for the case where scoped :ord…

…er was present
  • Loading branch information...
1 parent 84baada commit aa99bd19e187650eae5e7031176997f7215041bd @tarmo tarmo committed with jeremy Jul 15, 2008
Showing with 8 additions and 3 deletions.
  1. +8 −3 activerecord/lib/active_record/associations.rb
View
11 activerecord/lib/active_record/associations.rb
@@ -1478,10 +1478,15 @@ def construct_finder_sql_for_association_limiting(options, join_dependency)
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
@@ -1495,8 +1500,8 @@ def construct_finder_sql_for_association_limiting(options, join_dependency)
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

0 comments on commit aa99bd1

Please sign in to comment.