datamapper / dm-core

DataMapper - Core
http://datamapper.org/
MIT License
754 stars 153 forks source link

Cannot chain first and last on collection #201

Open UncleGene opened 12 years ago

UncleGene commented 12 years ago

Model.all.first(3).last returns last element of the whole collection, not expected third element

dkubb commented 12 years ago

It's possible that the method that handles "windowing" of the query is calculating things incorrectly.

After #first(3) the offset should be 0, and the limit should be 3. After #last, the offset should be changed to 2 and the limit changed to 1. I'm not sure what the value is (will need to look more deeply), but it's likely the problem.

The way queries are composed in DM1 may limit how far this can be fixed without breaking other use cases. I can confirm though that this problem does not exist in Veritas/DM2 due to how queries are composed.

UncleGene commented 12 years ago

In current code, last slices reversed query - and, thus, any chaining of last breaks slice offset/limit adjustment.

This looks connected to other bug report (no support for negative values in slice), if latter is fixed - former fix is trivial.

UncleGene commented 12 years ago

First step towards fix submitted as pull request https://github.com/datamapper/dm-core/issues/202