Commit c5f3319
feat: support Rails 8.1 in PolymorphicArrayValueExtension
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) <noreply@anthropic.com>1 parent ced3ea0 commit c5f3319
5 files changed
Lines changed: 29 additions & 2 deletions
File tree
- .github/workflows
- gemfiles
- lib/polymorphic_integer_type
- activerecord_5_0_0
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
3 | 9 | | |
4 | 10 | | |
5 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
14 | 22 | | |
15 | 23 | | |
16 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
0 commit comments