alxtskrnk@gmail.com
2013-Aug-18 17:04 UTC
on deprecation/removal of the distinct option to Relation#count
https://github.com/rails/rails/pull/9683#issuecomment-22827535
when distinct is intended as a parameter of the sql count function
(COUNT(DISTINCT DATE(attr))), it makes perfect sense for it to be a
parameter to the count method, particularly when you are counting
expressions.
When counting just records (*) and count takes no arguments,
`.distinct.count` reads ok, but when there''s an expression involved
`.count(''date(attr)'')`, distinct and the count expression
belong together
as arguments to count `.count(''date(attr)'', distinct: true)`,
as in SQL
`COUNT(DISTINCT DATE(attr)`
I think counting with expressions is sufficient reason for :distinct param
to remain.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.
alxtskrnk@gmail.com
2013-Aug-19 16:34 UTC
Re: on deprecation/removal of the distinct option to Relation#count
On Sunday, August 18, 2013 1:04:24 PM UTC-4, alxt...@gmail.com wrote:> > https://github.com/rails/rails/pull/9683#issuecomment-22827535 > > when distinct is intended as a parameter of the sql count function > (COUNT(DISTINCT DATE(attr))), it makes perfect sense for it to be a > parameter to the count method, particularly when you are counting > expressions. > > When counting just records (*) and count takes no arguments, > `.distinct.count` reads ok, but when there''s an expression involved > `.count(''date(attr)'')`, distinct and the count expression belong together > as arguments to count `.count(''date(attr)'', distinct: true)`, as in SQL > `COUNT(DISTINCT DATE(attr)` > > I think counting with expressions is sufficient reason for :distinct param > to remain. >though as rafaelfranca pointed out, `.count("DISTICT #{expr_str}")` should work, there does not seem to be any compelling reason for breaking `.count(expr_str, distinct: true)` -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.