aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-08-21 21:58:38 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-08-21 21:58:38 +0000
commit3566be47284053c8c7ea96bc361524147d4d1441 (patch)
tree3194118be43f849767cb34de8e9b4ed8adc4a1eb /activerecord/lib/active_record/base.rb
parent0e452bb02d7437a5e67fdb41f6a1f77289e7ddbd (diff)
downloadrails-3566be47284053c8c7ea96bc361524147d4d1441.tar.gz
rails-3566be47284053c8c7ea96bc361524147d4d1441.tar.bz2
rails-3566be47284053c8c7ea96bc361524147d4d1441.zip
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
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 61ba555553..44cbbc97cc 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -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