Remove patch for AR::Relation#primary_key in Rails 8.0+#238
Closed
Remove patch for AR::Relation#primary_key in Rails 8.0+#238
Conversation
5fc6a13 to
fb14c89
Compare
kymmt90
commented
Jan 15, 2026
osyo-manga
reviewed
Jan 16, 2026
a5-stable
approved these changes
Jan 16, 2026
fb14c89 to
3b25dcf
Compare
osyo-manga
reviewed
Jan 20, 2026
osyo-manga
reviewed
Jan 20, 2026
3b25dcf to
ae42c1b
Compare
Member
Author
ae42c1b to
fb1d32a
Compare
3445767 to
182898f
Compare
182898f to
6081fb6
Compare
Member
Author
|
Reworked on #243. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Only
AR::Relation'sprimary_keyis overridden withbitemporal_id_key.activerecord-bitemporal/lib/activerecord-bitemporal/bitemporal.rb
Lines 171 to 173 in 35410b4
Therefore, when
model.primary_keyis called in Rails 8.0+'s finder methods, it returns the originalprimary_keyvalue instead ofbitemporal_id_key. Additionally, this override can cause various other confusions.Changes
This PR removes the override of
AR::Relation#primary_keyin Rails 8.0+. The order of AR objects fetched by finder methods is kept as before thanks to #237.By removing the override of
primary_key,AR::Calculations#idsnow returns an array ofswapped_idinstead ofbitemporal_id. This is becauseAR::Relation::Calculations#idscallsprimary_keyon self.https://github.com/rails/rails/blob/v8.0.4/activerecord/lib/active_record/relation/calculations.rb#L371
This PR redefines
#idsto keep the previous behavior.