-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Ruby Drivers
-
None
-
None
-
None
-
None
-
None
-
None
In mongoid 9.0.2, .last method overrides .skip
In mongoid 7 and before the following code would return the next to last document:
ModelName.skip(1).last
In mongoid 9 (and 8 I believe) the above always returns the last document.
Looking at the code in mongoid contextual :
def retrieve_nth_to_last_with_limit(n, limit)
v = view.sort(inverse_sorting).{*}skip(n){*}.limit(limit || 1)
v = v.skip(n) if n > 0
raw_docs = v.to_a.reverse
process_raw_docs(raw_docs, limit)
end
I believe the skip in bold should be removed, it is overriding any skip value passed in.