public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Added HasManyAssociation#count that works like Base#count #413 [intinig]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@318 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Sun Jan 02 10:44:55 -0800 2005
commit  609ca177fa66ab0fbe19dd0cdcd7d8f1576cd9da
tree    ae898c43f99aaa588256152d31156176288611b4
parent  375568b7cb476285a9f8ea2c748d4987a477a119
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Added HasManyAssociation#count that works like Base#count #413 [intinig]
0
+
0
 * Fixed handling of binary content in blobs and similar fields for Ruby/MySQL and SQLite #409 [xal]
0
 
0
 * Added dynamic attribute-based finders as a cleaner way of getting objects by simple queries without turning to SQL.
...
47
48
49
 
 
 
 
 
 
 
 
 
 
 
50
51
52
...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
0
@@ -47,6 +47,17 @@
0
         end
0
       end
0
 
0
+ # Count the number of associated records. All arguments are optional.
0
+ def count(runtime_conditions = nil)
0
+ if @options[:finder_sql]
0
+ @association_class.count_by_sql(@finder_sql)
0
+ else
0
+ sql = @finder_sql
0
+ sql << " AND #{sanitize_sql(runtime_conditions)}" if runtime_conditions
0
+ @association_class.count(sql)
0
+ end
0
+ end
0
+
0
       # Find the first associated record. All arguments are optional.
0
       def find_first(conditions = nil, orderings = nil)
0
         find_all(conditions, orderings, 1).first
...
149
150
151
 
 
 
 
152
153
154
...
149
150
151
152
153
154
155
156
157
158
0
@@ -149,6 +149,10 @@
0
     @signals37.clients_of_firm.each {|f| }
0
   end
0
   
0
+ def test_counting
0
+ assert_equal 2, Firm.find_first.clients.count
0
+ end
0
+
0
   def test_finding
0
     assert_equal 2, Firm.find_first.clients.length
0
   end

Comments

    No one has commented yet.