Repository navigation
Rails 4 compatibility & thread safety - #15
Merged
Merged
Conversation
The signature changed in Rails 4, since the hash-style query syntax is deprecated. It now gets a proc or lambda for the scope. Also it's thread safe now.
This comment was marked as resolved.
This comment was marked as resolved.
See the documentation attached.
…ord-deprecated_finders`) The lambda is instance_exec'd on `klass.unscoped`, which is a `Relation`, not the model class. So bare all doesn't resolve to `Model.all` (which returns a Relation); it hits deprecated_finders' `Relation#all`, whose body is `apply_finder_options(args.first, true).to_a`. The array cast then errors because it's not a scope.
```
# (new, scope-block style)
has_many :x, -> { where(...) }, class_name: 'Y'
# (legacy finder-option style)
has_many :x, conditions: '...', order: '...'
```
In the legacy form Ruby binds the options hash to the `scope` slot. We must not relocate it, `activerecord-deprecated_finders` only translates legacy finder options (:conditions/:order/:include/...) into a real scope when they arrive in the `scope` position. Parse the args non-destructively and forward them in their original shape so both deprecated_finders (reads `scope`) and downstream has_many overrides that use `extract_options!` (read the trailing arg) see the hash where they expect it.
It assumed a scope is present only if `args.first` is callable. But Rails 4.2 implements `has_and_belongs_to_many` by internally calling `has_many name, nil, hm_options` (note the explicit nil scope followed by the options hash).
RDIL
marked this pull request as ready for review
July 17, 2026 14:46
hfsaito
approved these changes
Jul 17, 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.
Fixes GEN-6734
This was really painful
This PR: