First off, I love, love, love MetaWhere!
Second, I'm trying to return a count with groupings and SQL functions:
Client.select(:year[:date_of_birth].as('age')).group(:county, :age)
... works great. But adding .count to the end:
Client.select(:year[:date_of_birth].as('age')).group(:county, :age).count
SELECT COUNT(#<MetaWhere::Function:0x106fd0230>) AS count_metawhere_function_0x106fd0230, county AS county, age AS age FROM `clients` GROUP BY county,age
I've worked around it by using a COUNT() sql function in the select, but it's sloppier and forces me also to select the other fields and to do a map:
Client.select([
:count[Client.arel_table[:client_id]].as(:client_count),
:county,
:year[:date_of_birth].as('age')
]).
group(:county, :age).map {|c| [c.county, c.age, c.client_count]}
This works; I'm just wondering if I ran into a bug or I'm not using it right. Thanks!