aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/CHANGELOG.md
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-10-03 18:02:14 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-10-03 18:02:14 -0500
commitaa202adf6c78468c8e03efd11d84b71478de7b03 (patch)
tree8977d638cb7cc852c0b40b971ab07a66f64acb7b /activerecord/CHANGELOG.md
parente4e84fee8b9ecd63e1cc7b62beb577f8fe7ce35d (diff)
downloadrails-aa202adf6c78468c8e03efd11d84b71478de7b03.tar.gz
rails-aa202adf6c78468c8e03efd11d84b71478de7b03.tar.bz2
rails-aa202adf6c78468c8e03efd11d84b71478de7b03.zip
Count returns 0 without querying if parent is not saved
Patches `CollectionAssociation#count` to return 0 without querying if the parent record is new. Consider the following code: class Account has_many :dossiers end class Dossier belongs_to :account end a = Account.new a.dossiers.build # before patch a.dossiers.count # SELECT COUNT(*) FROM "dossiers" WHERE "dossiers"."account_id" IS NULL # => 0 # after a.dosiers.count # fires without sql query # => 0 Fixes #1856.
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r--activerecord/CHANGELOG.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 8ff4c4706c..2a0f1bf92a 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,22 @@
## Rails 4.0.0 (unreleased) ##
+* `CollectionAssociation#count` returns 0 without querying if the
+ parent record is new.
+
+ Before:
+
+ person.pets
+ # SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
+ # => 0
+
+ After:
+
+ person.pets
+ # fires without sql query
+ # => 0
+
+ *Francesco Rodriguez*
+
* Fix `reset_counters` crashing on `has_many :through` associations.
Fix #7822.