diff options
author | miloops <miloops@gmail.com> | 2008-11-21 19:20:33 -0300 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-12-01 20:22:31 +0100 |
commit | 97403ad5fdfcdfb2110c6f8fd0ebf43b7afc4859 (patch) | |
tree | 77998cf59255d49323d7f7063025ca895e162f62 /activerecord/lib/active_record/associations.rb | |
parent | 0c4ba90aa1ea6a8d386c724a55a31e63a13c46ab (diff) | |
download | rails-97403ad5fdfcdfb2110c6f8fd0ebf43b7afc4859.tar.gz rails-97403ad5fdfcdfb2110c6f8fd0ebf43b7afc4859.tar.bz2 rails-97403ad5fdfcdfb2110c6f8fd0ebf43b7afc4859.zip |
Add :having option to find, to use in combination with grouped finds. Also added to has_many and has_and_belongs_to_many associations.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1028 state:committed]
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 0546b76c63..3fbbea43ed 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -724,6 +724,8 @@ module ActiveRecord # Specify second-order associations that should be eager loaded when the collection is loaded. # [:group] # An attribute name by which the result should be grouped. Uses the <tt>GROUP BY</tt> SQL-clause. + # [:having] + # Combined with +:group+ this can be used to filter the records that a <tt>GROUP BY</tt> returns. Uses the <tt>HAVING</tt> SQL-clause. # [:limit] # An integer determining the limit on the number of rows that should be returned. # [:offset] @@ -1181,6 +1183,8 @@ module ActiveRecord # Specify second-order associations that should be eager loaded when the collection is loaded. # [:group] # An attribute name by which the result should be grouped. Uses the <tt>GROUP BY</tt> SQL-clause. + # [:having] + # Combined with +:group+ this can be used to filter the records that a <tt>GROUP BY</tt> returns. Uses the <tt>HAVING</tt> SQL-clause. # [:limit] # An integer determining the limit on the number of rows that should be returned. # [:offset] @@ -1553,7 +1557,7 @@ module ActiveRecord @@valid_keys_for_has_many_association = [ :class_name, :table_name, :foreign_key, :primary_key, :dependent, - :select, :conditions, :include, :order, :group, :limit, :offset, + :select, :conditions, :include, :order, :group, :having, :limit, :offset, :as, :through, :source, :source_type, :uniq, :finder_sql, :counter_sql, @@ -1609,7 +1613,7 @@ module ActiveRecord mattr_accessor :valid_keys_for_has_and_belongs_to_many_association @@valid_keys_for_has_and_belongs_to_many_association = [ :class_name, :table_name, :join_table, :foreign_key, :association_foreign_key, - :select, :conditions, :include, :order, :group, :limit, :offset, + :select, :conditions, :include, :order, :group, :having, :limit, :offset, :uniq, :finder_sql, :counter_sql, :delete_sql, :insert_sql, :before_add, :after_add, :before_remove, :after_remove, @@ -1658,7 +1662,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]) - add_group!(sql, options[:group], scope) + add_group!(sql, options[:group], options[:having], scope) add_order!(sql, options[:order], scope) add_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections) add_lock!(sql, options, scope) @@ -1714,7 +1718,7 @@ module ActiveRecord end add_conditions!(sql, options[:conditions], scope) - add_group!(sql, options[:group], scope) + add_group!(sql, options[:group], options[:having], scope) if order && is_distinct connection.add_order_by_for_association_limiting!(sql, :order => order) |