aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-11-10 16:36:01 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-11-10 16:36:01 +0000
commit3309268120fade0cd643750a4bedf95097cbced6 (patch)
treea014ca1505d05d4e5833e396efec357f2b7b0ad6 /activerecord/lib/active_record/base.rb
parent3488ff6fc6aa091821088df47ee0ca3ebdd594f0 (diff)
downloadrails-3309268120fade0cd643750a4bedf95097cbced6.tar.gz
rails-3309268120fade0cd643750a4bedf95097cbced6.tar.bz2
rails-3309268120fade0cd643750a4bedf95097cbced6.zip
Add :group option, correspond to GROUP BY, to the find method and to the has_many association. Closes #2818.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2974 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 06ac4459de..47b8b6b92b 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -363,6 +363,7 @@ module ActiveRecord #:nodoc:
#
# * <tt>:conditions</tt>: An SQL fragment like "administrator = 1" or [ "user_name = ?", username ]. See conditions in the intro.
# * <tt>:order</tt>: An SQL fragment like "created_at DESC, name".
+ # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause.
# * <tt>:limit</tt>: An integer determining the limit on the number of rows that should be returned.
# * <tt>:offset</tt>: An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
# * <tt>:joins</tt>: An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id". (Rarely needed).
@@ -391,6 +392,7 @@ module ActiveRecord #:nodoc:
# Person.find(:all, :conditions => [ "category IN (?)", categories], :limit => 50)
# Person.find(:all, :offset => 10, :limit => 10)
# Person.find(:all, :include => [ :account, :friends ])
+ # Person.find(:all, :group => "category")
def find(*args)
options = extract_options_from_args!(args)
@@ -926,6 +928,7 @@ module ActiveRecord #:nodoc:
sql = "SELECT #{options[:select] || '*'} FROM #{table_name} "
add_joins!(sql, options)
add_conditions!(sql, options[:conditions])
+ sql << " GROUP BY #{options[:group]} " if options[:group]
sql << " ORDER BY #{options[:order]} " if options[:order]
add_limit!(sql, options)
sql
@@ -1171,7 +1174,7 @@ module ActiveRecord #:nodoc:
end
def validate_find_options(options)
- options.assert_valid_keys [:conditions, :include, :joins, :limit, :offset, :order, :select, :readonly]
+ options.assert_valid_keys [:conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group]
end
def encode_quoted_value(value)