Permalink
Browse files

Fixed that eager loading queries and with_scope should respect the :g…

…roup option [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7355 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
dhh committed Aug 21, 2007
1 parent 0e452bb commit 3566be47284053c8c7ea96bc361524147d4d1441
View
@@ -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]
@@ -1292,8 +1292,7 @@ def construct_finder_sql_with_included_associations(options, join_dependency)
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 @@ def construct_finder_sql_for_association_limiting(options, join_dependency)
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
@@ -1112,8 +1112,7 @@ def construct_finder_sql(options)
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 @@ def add_order!(sql, order, scope = :auto)
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 @@ def with_scope(method_scoping = {}, action = :merge, &block)
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

0 comments on commit 3566be4

Please sign in to comment.