aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorTarmo Tänav <tarmo@itech.ee>2008-07-15 05:17:06 +0300
committerJeremy Kemper <jeremy@bitsweat.net>2008-07-14 22:44:58 -0700
commit8c91b767c0f36e9d767eb230ec42b111e57d90da (patch)
treea7fdfc72ea67d2992e5776703efaf87a16b49a07 /activerecord/lib/active_record/associations.rb
parent34510456585216004e483b79beeea3ddc3eb4de6 (diff)
downloadrails-8c91b767c0f36e9d767eb230ec42b111e57d90da.tar.gz
rails-8c91b767c0f36e9d767eb230ec42b111e57d90da.tar.bz2
rails-8c91b767c0f36e9d767eb230ec42b111e57d90da.zip
Fixed postgresql limited eager loading for the case where scoped :order was present
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index d43e07ab4e..7ad7802cbc 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -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