diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-04-25 05:25:04 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-04-25 05:25:04 +0000 |
commit | 4251662c1a4dbec8c69d4ab1b677950a0b4cfb58 (patch) | |
tree | b3daa61acc884eddb42d1f0928842c21803b7638 /activerecord/lib/active_record/associations.rb | |
parent | abc2dba1ed15d9b30900890fdf4dee10c4f60a02 (diff) | |
download | rails-4251662c1a4dbec8c69d4ab1b677950a0b4cfb58.tar.gz rails-4251662c1a4dbec8c69d4ab1b677950a0b4cfb58.tar.bz2 rails-4251662c1a4dbec8c69d4ab1b677950a0b4cfb58.zip |
Allow all calculations to take the :include option, not just COUNT (closes #4840) [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4264 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index c0fdca3da9..4a637d5dab 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -966,14 +966,6 @@ module ActiveRecord end end - def count_with_associations(options = {}) - catch :invalid_query do - join_dependency = JoinDependency.new(self, merge_includes(scope(:find, :include), options[:include]), options[:joins]) - return count_by_sql(construct_counter_sql_with_included_associations(options, join_dependency)) - end - 0 - end - def find_with_associations(options = {}) catch :invalid_query do join_dependency = JoinDependency.new(self, merge_includes(scope(:find, :include), options[:include]), options[:joins]) @@ -1117,31 +1109,6 @@ module ActiveRecord "#{name} Load Including Associations" ) end - - def construct_counter_sql_with_included_associations(options, join_dependency) - scope = scope(:find) - sql = "SELECT COUNT(DISTINCT #{table_name}.#{primary_key})" - - # A (slower) workaround if we're using a backend, like sqlite, that doesn't support COUNT DISTINCT. - if !Base.connection.supports_count_distinct? - sql = "SELECT COUNT(*) FROM (SELECT DISTINCT #{table_name}.#{primary_key}" - end - - sql << " FROM #{table_name} " - sql << join_dependency.join_associations.collect{|join| join.association_join }.join - - add_joins!(sql, options, scope) - 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_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections) - - if !Base.connection.supports_count_distinct? - sql << ")" - end - - return sanitize_sql(sql) - end def construct_finder_sql_with_included_associations(options, join_dependency) scope = scope(:find) |