public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/ddollar/rails.git
Fixed that HasManyAssociation#count was using :finder_sql rather than 
: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
dhh (author)
Sun Mar 06 03:53:49 -0800 2005
commit  5e44eda7872c6ee33e0d09a4b9fd78896e14b95a
tree    b64009226562aa04ce107692e726f545b3f9895f
parent  dfac1cea3d851000116a23ab14c2b1ae981f7a12
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Fixed that HasManyAssociation#count was using :finder_sql rather than :counter_sql if it was available #445 [Scott Barron]
0
+
0
 * 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)
0
 
0
 * Added MacroReflection#macro which will return a symbol describing the macro used (like :composed_of or :has_many) #718, #248 [james@slashetc.com]
...
33
34
35
36
 
 
 
37
38
39
...
33
34
35
 
36
37
38
39
40
41
0
@@ -33,7 +33,9 @@ module ActiveRecord
0
 
0
       # Count the number of associated records. All arguments are optional.
0
       def count(runtime_conditions = nil)
0
- if @options[:finder_sql]
0
+ if @options[:counter_sql]
0
+ @association_class.count_by_sql(@counter_sql)
0
+ elsif @options[:finder_sql]
0
           @association_class.count_by_sql(@finder_sql)
0
         else
0
           sql = @finder_sql
...
6
7
8
9
 
10
11
12
...
6
7
8
 
9
10
11
12
0
@@ -6,7 +6,7 @@ end
0
 
0
 
0
 class Firm < Company
0
- has_many :clients, :order => "id", :dependent => true
0
+ 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' )"
0
   has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
0
   has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
0
   has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"

Comments

    No one has commented yet.