This project is archived and is in readonly mode.
Count on has_many associations doesn't respect the association :limit and :offset options
-
Tarmo Tänav
- Tag set to activerecord, bug, edge, has_many, tested, tests
Do you have ideas on how calculations should be implemented with limit or offset? You can't just throw them at the end of the SQL because limit/offset in that case would apply to the result of the calculation, not the input of it that the option on has_many would imply.
One approach that I can think of is using a subquery, but it is not at all pretty and I'm not sure if all databases can support it:
SELECT COUNT(*) FROM (SELECT * FROM table LIMIT x OFFSET y) AS z;
-
Jeremy Kemper
- Milestone set to 2.1.1
- State changed from new to open
- Assigned user set to Jeremy Kemper
The count method could check for scoped :offset and :limit and do [[count_sql - offset, 0].max, limit].min instead of counting rows.
-
Tarmo Tänav
Implemented as per Jeremy's suggestion, included the test in the patch as it didn't apply cleanly.
-
Repository
- State changed from open to resolved
- Tag changed from activerecord, bug, edge, has_many, tested, tests to activerecord, bug, edge, has_many, patch, tested, tests
(from [367942d93bbb99aa2c2f8dc3900cb7c3f2ba4c65]) Implement count limit/offset support for has_many associations
[#348 state:resolved]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
-
Repository
(from [96c6fe084228d570dad80e3100830edb2bc0448d]) Implement count limit/offset support for has_many associations
[#348 state:resolved]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
