Fixed that eager loading queries and with_scope should respect the :group option [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7355 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson
2007-08-21 21:58:38 +00:00
parent 0e452bb02d
commit 3566be4728
3 changed files with 17 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
*SVN*
* Fixed that eager loading queries should respect the :group option as well [DHH]
* Fixed that eager loading queries and with_scope should respect the :group option [DHH]
* Improve performance and functionality of the postgresql adapter. Closes #8049 [roderickvd]

View File

@@ -1292,8 +1292,7 @@ module ActiveRecord
add_conditions!(sql, options[:conditions], scope)
add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit])
sql << "GROUP BY #{options[:group]} " if options[:group]
add_group!(sql, options[:group], scope)
add_order!(sql, options[:order], scope)
add_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections)
add_lock!(sql, options, scope)
@@ -1333,13 +1332,13 @@ module ActiveRecord
end
add_conditions!(sql, options[:conditions], scope)
sql << " GROUP BY #{options[:group]} " if options[:group]
add_group!(sql, options[:group], scope)
if options[:order]
if is_distinct
connection.add_order_by_for_association_limiting!(sql, options)
else
sql << "ORDER BY #{options[:order]}"
add_order!(sql, options[:order], scope)
end
end

View File

@@ -1112,8 +1112,7 @@ module ActiveRecord #:nodoc:
add_joins!(sql, options, scope)
add_conditions!(sql, options[:conditions], scope)
sql << " GROUP BY #{options[:group]} " if options[:group]
add_group!(sql, options[:group], scope)
add_order!(sql, options[:order], scope)
add_limit!(sql, options, scope)
add_lock!(sql, options, scope)
@@ -1148,6 +1147,17 @@ module ActiveRecord #:nodoc:
sql << " ORDER BY #{scoped_order}" if scoped_order
end
end
def add_group!(sql, group, scope = :auto)
scope = scope(:find) if :auto == scope
scoped_group = scope[:group] if scope
if group
sql << " GROUP BY #{group}"
elsif scoped_group
sql << " GROUP BY #{scoped_group}"
end
end
# The optional scope argument is for the current :find scope.
def add_limit!(sql, options, scope = :auto)
@@ -1383,7 +1393,7 @@ module ActiveRecord #:nodoc:
method_scoping.assert_valid_keys([ :find, :create ])
if f = method_scoping[:find]
f.assert_valid_keys([ :conditions, :joins, :select, :include, :from, :offset, :limit, :order, :readonly, :lock ])
f.assert_valid_keys([ :conditions, :joins, :select, :include, :from, :offset, :limit, :order, :group, :readonly, :lock ])
set_readonly_option! f
end