diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-29 00:07:46 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-29 00:07:46 +0530 |
commit | 91e28aae8649c503e81d66ad6829403ccc2c6571 (patch) | |
tree | ed51b3519723cc1966e1faa31d0a2478f8b2c0e0 /activerecord/lib/active_record/base.rb | |
parent | e8ca22d129c1e93574e770dd69dc964be6686469 (diff) | |
download | rails-91e28aae8649c503e81d66ad6829403ccc2c6571.tar.gz rails-91e28aae8649c503e81d66ad6829403ccc2c6571.tar.bz2 rails-91e28aae8649c503e81d66ad6829403ccc2c6571.zip |
Add Model.having and Relation#having
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 3135234706..767109474d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -652,7 +652,7 @@ module ActiveRecord #:nodoc: end end - delegate :select, :group, :order, :limit, :joins, :where, :preload, :eager_load, :from, :lock, :readonly, :to => :scoped + delegate :select, :group, :order, :limit, :joins, :where, :preload, :eager_load, :from, :lock, :readonly, :having, :to => :scoped # A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in all the # same arguments to this method as you can to <tt>find(:first)</tt>. @@ -1566,7 +1566,8 @@ module ActiveRecord #:nodoc: joins(construct_join(options[:joins], scope)). where(construct_conditions(options[:conditions], scope)). select(options[:select] || (scope && scope[:select]) || default_select(options[:joins] || (scope && scope[:joins]))). - group(construct_group(options[:group], options[:having], scope)). + group(options[:group] || (scope && scope[:group])). + having(options[:having] || (scope && scope[:having])). order(construct_order(options[:order], scope)). limit(construct_limit(options[:limit], scope)). offset(construct_offset(options[:offset], scope)). @@ -1611,18 +1612,6 @@ module ActiveRecord #:nodoc: end end - def construct_group(group, having, scope) - sql = '' - if group - sql << group.to_s - sql << " HAVING #{sanitize_sql_for_conditions(having)}" if having - elsif scope && (scoped_group = scope[:group]) - sql << scoped_group.to_s - sql << " HAVING #{sanitize_sql_for_conditions(scope[:having])}" if scope[:having] - end - sql - end - def construct_order(order, scope) orders = [] |