Repository navigation
Fix Relation#load to return self instead of an Array - #267
Merged
degwinthegreat merged 2 commits intoJul 9, 2026
Merged
Conversation
ActiveRecord::Relation#load is expected to return the relation itself, but the bitemporal override ended with `records.each`, whose return value (the records Array) leaked out when valid_datetime or transaction_datetime is set, e.g. `Employee.valid_at(time).load`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
kymmt90
reviewed
Jul 9, 2026
The variable holds the relation itself returned by `super` (Relation#load returns self), not an array of records. Renaming it clarifies that #load returns the relation, as suggested in the PR review. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
ActiveRecord::Relation#load is expected to return the relation itself (self), not the records:
https://github.com/rails/rails/blob/v8.1.3/activerecord/lib/active_record/relation.rb#L1193-L1206
However, the bitemporal override of #load ended with records.each. Since Relation#each is delegated to records (the loaded Array) by ActiveRecord::Delegation, records.each returns the Array — which leaked out as the return value of #load when valid_datetime or transaction_datetime is set:
https://github.com/rails/rails/blob/v8.1.3/activerecord/lib/active_record/relation/delegation.rb#L100-L103
Fix
Return records (the relation returned by super) at the end of #load, matching Active Record's contract that load returns self.
🤖 Generated with Claude Code