Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Background
We're using
disable_joins
very successfully — thank you! — but discovered a bug when using non-integer primary keys. Some combinations of non-integer primary keys, has many through associations and order clauses invokes a disable-joins specific association cache which returns nil records. I discovered it's due to a rogue#to_i
.This PR uses the attribute type to cast values when reaching into the cache instead of presuming ids are always integers and causes appropriate records to be returned. Existing tests continue to pass.
I've added a test which demonstrates the issue, but it's pretty heavy and I'm not sure is the most appropriate place. Please advise if this test belongs somewhere else.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature.Minor bug fixes and documentation changes should not be included.