rails/rails — pull request #6978 by frodsan (2012-07-05 20:14:46+00:00)
Title: Count return 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

a.dossiers.count
# SELECT COUNT(*) FROM "dossiers" WHERE "dossiers"."account_id" IS NULL
# => 0

a.dosiers.count # fires without sql query
# => 0

Fixes #1856.