`#count` in conjunction with `#uniq` performs distinct count. #9078

Merged
merged 1 commit into from Jan 26, 2013

Projects

None yet

4 participants

@senny
Member
senny commented Jan 25, 2013

This is a fix for #6865

It makes sure that we perform a COUNT(DISTINCT *) when Relation.uniq.count is used. While writing up the patch we noticed that the "count" code path is very different from the other calculations. I wanted to submit a small patch for the problem but we will try to clean up the count code in a second PR.

@senny
Member
senny commented Jan 25, 2013

@rafaelfranca @jonleighton could you take a look? Also what do you think about a backport? Too risky?

@rafaelfranca rafaelfranca commented on an outdated diff Jan 25, 2013
activerecord/lib/active_record/relation/calculations.rb
if operation == "count"
column_name ||= (select_for_count || :all)
-
@rafaelfranca
rafaelfranca Jan 25, 2013 Ruby on Rails member

Please don't remove this line

@carlosantoniodasilva

Seems good.

@luke-gru

Ran into this issue just the other day. Thanks!

@senny
Member
senny commented Jan 26, 2013

@rafaelfranca @carlosantoniodasilva changes are made. Could you check again?

@rafaelfranca rafaelfranca merged commit 647d18c into rails:master Jan 26, 2013
@rafaelfranca
Member

❤️ 💚 💙 💛 💜

@senny senny deleted the senny:6865_ar_count_with_uniq branch Jan 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment