From 4a7b4f88cd3fc10ab56edc3f88d5db0c4f871dc9 Mon Sep 17 00:00:00 2001 From: Klas Eskilson Date: Tue, 3 Jan 2017 16:24:42 -0800 Subject: Use `count(:all)` in HasManyAssociation#count_records Problem: Calling `count` on an association can cause invalid SQL queries to be created where the `SELECT COUNT(a, b, c)` function receives multiple columns. This will cause a `StatementInvalid` exception later on. Solution: Use `count(:all)`, which generates a `SELECT COUNT(*)...` query independently of the association. This also includes a test case that, before the fix, broke. --- activerecord/test/models/company.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/test/models/company.rb') diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 20e37710e7..7ab969cdf1 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -85,6 +85,8 @@ class Firm < Company has_many :association_with_references, -> { references(:foo) }, class_name: "Client" + has_many :developers_with_select, -> { select("id, name, first_name") }, class_name: "Developer" + has_one :lead_developer, class_name: "Developer" has_many :projects -- cgit v1.2.3