Support Rails 8.1 in PolymorphicArrayValueExtension#68
Merged
raymasiclat merged 2 commits intomasterfrom Apr 30, 2026
Merged
Conversation
Rails 8.1 changed `ActiveRecord::PredicateBuilder::PolymorphicArrayValue#initialize`
from `(associated_table, values)` to `(reflection, values)`, dropping the
`@associated_table` ivar that this gem reads via
`@associated_table.send(:reflection)` in `type_to_ids_mapping`. Without an
update, every polymorphic-array predicate query (e.g. `Model.where(thing: [a, b])`)
raises `NoMethodError: undefined method 'reflection' for nil` on Rails 8.1.
The minimal fix: read `@reflection` directly when set (Rails 8.1+), fall back to
`@associated_table.send(:reflection)` for older Rails versions. The rest of the
method runs unchanged.
This also adds Gemfile.rails-8.1-stable to the CI matrix so future regressions
are caught upstream rather than in downstream apps.
## Verification
The existing spec at `polymorphic_integer_type_spec.rb:135` ("properly finds
the object when passing an array of sources") exercises exactly this code path:
Link.where(source: [source])
Verified locally:
- Rails 8.0: 41/41 passing
- Rails 8.1: 41/41 passing
- Rails 8.1 *without* this fix: 1 failure (the array-of-sources test) —
proves the test catches the regression and the fix resolves it.
Downstream apps (clio/accounting, clio/manage, clio/themis, etc.) currently
maintain in-app monkey patches for this; bumping to 3.5.0 lets them delete
those.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The existing array-of-sources test only exercises a single-type array (`Link.where(source: [cat])`). The fix's value also covers multi-type arrays (`Link.where(source: [cat, dog])`) — a broader branch of `type_to_ids_mapping` where the result hash spans multiple keys. Locks in coverage on both Rails 8.0 (backwards compat) and 8.1. Suggested by code review. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
anthonyoconnorclio
approved these changes
Apr 30, 2026
ChrisRoversClio
approved these changes
Apr 30, 2026
ChrisRoversClio
left a comment
There was a problem hiding this comment.
manual and automated review. CI green. tests look good. LGTM
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.
Rails 8.1 changed
ActiveRecord::PredicateBuilder::PolymorphicArrayValue#initializefrom(associated_table, values)to(reflection, values), dropping the@associated_tableivar that this gem reads via@associated_table.send(:reflection)intype_to_ids_mapping. Without an update, every polymorphic-array predicate query (Model.where(thing: [a, b])) raisesNoMethodError: undefined method 'reflection' for nilon Rails 8.1.Fix
Read
@reflectionwhen set (Rails 8.1+), fall back to@associated_table.send(:reflection)for older Rails versions. The rest oftype_to_ids_mappingruns unchanged.Also in this PR
gemfiles/Gemfile.rails-8.1-stableto the CI matrix (with Ruby 3.0/3.1 exclusions — Rails 8.1 requires 3.2+)3.5.0Verification
The existing spec at
spec/polymorphic_integer_type_spec.rb:135("properly finds the object when passing an array of sources") exercises exactly this code path:Verified locally:
Downstream impact
Several Clio repos currently need (or are about to need) in-app monkey patches for this on Rails 8.1 — clio/accounting (PR #15318), and likely clio/themis, clio/grow. Publishing 3.5.0 lets each of those bump the gem dep and prevent the need for in-app patches.
🤖 Generated with Claude Code