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
ActiveRecord::Relation#last ignores limit #371
Comments
What would you expect it to return if there were less than the limit number of objects? The reason limit is ignored is because |
baroquebobcat
added a commit
to baroquebobcat/rails
that referenced
this issue
May 7, 2011
if a query contains a limit or an offset, ActiveRecord::FinderMethods#find_last had inconsistent behavior. If the records were loaded, it returned the last record in the cached list. If they were not, it reversed the order of the query and changed the limit to one. If the earlier limit was less than the total matching the query in the db, it would return a different record than if the records had been cached. This commit changes find_last so that it loads the records when getting the last record on a query containing a limit or an offset, which makes the behavior consistent.
I put together a patch #451 |
Closing this in favor of the pull request. |
jonleighton
pushed a commit
that referenced
this issue
May 8, 2011
if a query contains a limit or an offset, ActiveRecord::FinderMethods#find_last had inconsistent behavior. If the records were loaded, it returned the last record in the cached list. If they were not, it reversed the order of the query and changed the limit to one. If the earlier limit was less than the total matching the query in the db, it would return a different record than if the records had been cached. This commit changes find_last so that it loads the records when getting the last record on a query containing a limit or an offset, which makes the behavior consistent.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
limit
option is ignored when calling#last
on an ActiveRecord::Relation object:The text was updated successfully, but these errors were encountered: