diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-03 17:28:24 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-04 13:34:38 -0300 |
commit | 98967293cfef14a70281b47c4a07b5318f94d668 (patch) | |
tree | b16eed0d3b545ad6deaec6e80be4eed6b25f92ce /activerecord/lib | |
parent | 95369a5921a87988fbcb1b1d66a68255f3cf8924 (diff) | |
download | rails-98967293cfef14a70281b47c4a07b5318f94d668.tar.gz rails-98967293cfef14a70281b47c4a07b5318f94d668.tar.bz2 rails-98967293cfef14a70281b47c4a07b5318f94d668.zip |
Merge pull request #6978 from frodsan/count_nosql_unsaved_parent
Count returns 0 without querying if parent is not saved
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 3604d98015..67a1e457be 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -190,6 +190,8 @@ module ActiveRecord # association, it will be used for the query. Otherwise, construct options and pass them with # scope to the target class's +count+. def count(column_name = nil, count_options = {}) + return 0 if owner.new_record? + column_name, count_options = nil, column_name if column_name.is_a?(Hash) if options[:counter_sql] || options[:finder_sql] |