This project is archived and is in readonly mode.
Count calculations should respect scoped selects
-
Repository
- State changed from new to resolved
- Tag changed from activerecord, calculations, count, named_scope to activerecord, calculations, count, named_scope, patch
(from [6543426c73fa9ccf3649d7cbacbbb0fda9b6a099]) Ensure calculations respect scoped :select [#1334 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
-
Mislav
- Tag changed from activerecord, calculations, count, named_scope, patch to activerecord, bug, calculations, count, named_scope, patch, regression
This breaks counts on scoped associations:
author.posts.count # => works author.posts.scoped(:conditions => '1=1') # => FAIL -
Mislav
Uh, the second line in my example should have
count,size,empty?or whatever method at the end to trigger a COUNT query.I also forgot to state the error message: Mysql::Error (bad syntax). There is a join (hmt association) and this SELECT part is generated:
SELECT count(`posts`.*) AS ...This is invalid SQL, it should be "count(posts.id)".
-
Ian Terrell
Attached is a patch that includes a failing test case.
-
CancelProfileIsBroken
- State changed from resolved to open
- Assigned user set to Pratik
-
Ian Terrell
- Assigned user cleared.
The previous attachment was just a "git diff." Attached is a properly formatted patchfile to add my failing test.
-
Miha Filej
Workaround: #2189
-
Steven Soroka
this patch caused a bug with scopes and has-many-through's, see card #2310
-
Michael Koziarski
- Milestone cleared.
I'm reverting this in 2-3-stable so we can have a point release.
However I'm leaving this open and targetting 3.0 so we can try and fix the original bug.
-
Wolfram Arnold
I wrote up something similar in #1652
It was suggested to me to implement the :counter_sql option for named_scope instead. ActiveRecord::Base#find supports that too.
-
Pratik
- Assigned user changed from Pratik to Michael Koziarski
-
David Cuddeback
I have a patch that fixes this for the
2-3-stablebranch. I used the tests from Ian Terrell's patch and added one that addresses Mislav's comment. -
Jared McFarland
Is this ticket still open? I couldn't reproduce the bug in Rails 3.1
