Skip to content

Cannot chain first and last on collection #201

Open
UncleGene opened this Issue May 22, 2012 · 3 comments

2 participants

@UncleGene

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

@dkubb
DataMapper member
dkubb commented May 23, 2012

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

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

First step towards fix submitted as pull request
#202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.