Skip to content

Commit

Permalink
Fixed that HasManyAssociation#count was using :finder_sql rather than…
Browse files Browse the repository at this point in the history
… :counter_sql if it was available #445 [Scott Barron]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@834 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Mar 6, 2005
1 parent dfac1ce commit 5e44eda
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN* *SVN*


* Fixed that HasManyAssociation#count was using :finder_sql rather than :counter_sql if it was available #445 [Scott Barron]

* Added better defaults for composed_of, so statements like composed_of :time_zone, :mapping => %w( time_zone time_zone ) can be written without the mapping part (it's now assumed) * Added better defaults for composed_of, so statements like composed_of :time_zone, :mapping => %w( time_zone time_zone ) can be written without the mapping part (it's now assumed)


* Added MacroReflection#macro which will return a symbol describing the macro used (like :composed_of or :has_many) #718, #248 [james@slashetc.com] * Added MacroReflection#macro which will return a symbol describing the macro used (like :composed_of or :has_many) #718, #248 [james@slashetc.com]
Expand Down
Expand Up @@ -33,7 +33,9 @@ def find_all(runtime_conditions = nil, orderings = nil, limit = nil, joins = nil


# Count the number of associated records. All arguments are optional. # Count the number of associated records. All arguments are optional.
def count(runtime_conditions = nil) def count(runtime_conditions = nil)
if @options[:finder_sql] if @options[:counter_sql]
@association_class.count_by_sql(@counter_sql)
elsif @options[:finder_sql]
@association_class.count_by_sql(@finder_sql) @association_class.count_by_sql(@finder_sql)
else else
sql = @finder_sql sql = @finder_sql
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/fixtures/company.rb
Expand Up @@ -6,7 +6,7 @@ class Company < ActiveRecord::Base




class Firm < Company class Firm < Company
has_many :clients, :order => "id", :dependent => true has_many :clients, :order => "id", :dependent => true, :counter_sql => "SELECT COUNT(*) FROM companies WHERE firm_id = 1 AND (type = 'Client' OR type = 'SpecialClient' OR type = 'VerySpecialClient' )"
has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC" has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id" has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
Expand Down

0 comments on commit 5e44eda

Please sign in to comment.