This project is archived and is in readonly mode.
count method doesn't work with specified conditions
-
Jan Xie
- Assigned user set to Jeremy Kemper
-
Jeremy Kemper
We avoid touching custom finder_sql since appending " AND conditions" may just break the query.
The patch has a passing test case. Does it fail for other uses of finder_ or counter_sql?
-
Jan Xie
Though I think it will work at most time, yes it will break some finder_sql. To make it works in all cases, a mini sql parser need to be introduced, which doesn't look like a good option :)
-
Dan Pickett
- Tag changed from active_record, conditions, count to active_record, bugmash, conditions, count
-
Gavin Stark
If modifications to the conditions of an association using a finder_sql are not allowed, then they should not be silently ignored. Perhaps an exception could be raised which would at least tell the developer something rather than executing and returning unexpected results?
-
Rohit Arondekar
Any updates to this ticket?
-
Neeraj Singh
- Importance changed from to
After this ticket was created Jeremy said "We avoid touching custom finder_sql since appending " AND conditions" may just break the query."
+1 for that.
I would agree with Gavin that raising an exception should be a reasonable compromise.
Jeremy any thoughts on how we should proceed on this one.
-
Jeremy Kemper
- State changed from new to open
Failing fast -- raising an exception -- would be great. Patch + test welcome!
-
Neeraj Singh
- Tag changed from active_record, bugmash, conditions, count to active_record, bugmash, conditions, count, patch
Attached is patch with test.
-
Neeraj Singh
- Assigned user changed from Jeremy Kemper to José Valim
-
Repository
- State changed from open to resolved
(from [edb5401039ee15c37b201244c5dbf660bed51fb4]) count method should not take options if it is operated on has_many association which has finder_sql or counter_sql
[#2395 count method doesn't work with specified conditions state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/edb5401039ee15c37b201244c5dbf6...
