Localize patch for AR::Relation#primary_key in Rails 8.0+#243
Merged
Conversation
krororo
reviewed
Feb 9, 2026
4b6ed29 to
e92d946
Compare
e92d946 to
2179a7d
Compare
2179a7d to
d1c4328
Compare
krororo
approved these changes
Feb 24, 2026
Collaborator
krororo
left a comment
There was a problem hiding this comment.
I've confirmed the changes. It looks good to me.
osyo-manga
reviewed
Feb 25, 2026
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.
Rework of #238.
Problem
Only
AR::Relation'sprimary_keyis overridden withbitemporal_id_keyglobally.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 global 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 global override of
primary_key,AR::Calculations#ids/#exists?now usesswapped_idinstead ofbitemporal_id. This is because those methods callsprimary_keyon self.#ids: https://github.com/rails/rails/blob/v8.0.4/activerecord/lib/active_record/relation/calculations.rb#L371#exists?: https://github.com/rails/rails/blob/v8.0.4/activerecord/lib/active_record/relation/finder_methods.rb#L452This PR redefines
#idsand#exists?to overrideprimary_keylocally as#finddoes.