- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.4k
 
          MONGOID-5863 #last overrides #skip
          #5975
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This was being set even if n==0, which overrode any previously declared skip.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| 
           Assigned   | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record, I'm unsure why this is expected to return the nth-from-last element, but I agree with fixing the inadvertent BC break and look at this separately.
let's take this opportunity to simplify the GHA test workflow
| 
           By the way, I still haven't upgraded from Mongoid 7 due to concern over bugs like this (as well as performance issues). I am thinking to try upgrading soon, I will likely find more things.  | 
    
| 
           Regression found, as expected: https://jira.mongodb.org/browse/MONGOID-5865  | 
    
| it "returns the nth from last element" do | ||
| expect(context.skip(1).last).to eq(depeche_mode) | ||
| end | ||
| end | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method has sort(inverse_sorting) and then later v.to_a.reverse, which ensure the ordering in the case that multiple docs are returned.
Is this covered by tests? i.e. ensuring correct document ordering the result for multiple docs?
- combining 
skip(n)withlimit(m)(where n, m > 1) last(n)(where n > 1)
* remove redundant skip() This was being set even if n==0, which overrode any previously declared skip. * GHA is retiring ubuntu-20.04 let's take this opportunity to simplify the GHA test workflow * try and fix syntax error * try again
* remove redundant skip() This was being set even if n==0, which overrode any previously declared skip. * GHA is retiring ubuntu-20.04 let's take this opportunity to simplify the GHA test workflow * try and fix syntax error * try again
Prior to Mongoid 8.1,
Model.skip(1).lastwould return the next-to-last document. A refactoring in 8.1 resulted in this breaking, due to an extraneous call to#skipthat would override any other invocation of#skip.Summary
Fixes
Model.skip(1).lastso it again returns the next-to-last document, instead of just the last document.