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
上级 375568b7
*SVN*
* Added HasManyAssociation#count that works like Base#count #413 [intinig]
* Fixed handling of binary content in blobs and similar fields for Ruby/MySQL and SQLite #409 [xal]
* Added dynamic attribute-based finders as a cleaner way of getting objects by simple queries without turning to SQL.
......
......@@ -47,6 +47,17 @@ def find_all(runtime_conditions = nil, orderings = nil, limit = nil, joins = nil
end
end
# Count the number of associated records. All arguments are optional.
def count(runtime_conditions = nil)
if @options[:finder_sql]
@association_class.count_by_sql(@finder_sql)
else
sql = @finder_sql
sql << " AND #{sanitize_sql(runtime_conditions)}" if runtime_conditions
@association_class.count(sql)
end
end
# Find the first associated record. All arguments are optional.
def find_first(conditions = nil, orderings = nil)
find_all(conditions, orderings, 1).first
......
......@@ -149,6 +149,10 @@ def force_signal37_to_load_all_clients_of_firm
@signals37.clients_of_firm.each {|f| }
end
def test_counting
assert_equal 2, Firm.find_first.clients.count
end
def test_finding
assert_equal 2, Firm.find_first.clients.length
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册