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-03 17:28:24 -0700 |
commit | 3a63fe30935fab14071d3ca39869ed355ce52c1b (patch) | |
tree | 8977d638cb7cc852c0b40b971ab07a66f64acb7b /activerecord/lib | |
parent | e4e84fee8b9ecd63e1cc7b62beb577f8fe7ce35d (diff) | |
parent | aa202adf6c78468c8e03efd11d84b71478de7b03 (diff) | |
download | rails-3a63fe30935fab14071d3ca39869ed355ce52c1b.tar.gz rails-3a63fe30935fab14071d3ca39869ed355ce52c1b.tar.bz2 rails-3a63fe30935fab14071d3ca39869ed355ce52c1b.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 fe3e5b00f7..96270ec0e9 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -174,6 +174,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] |