Skip to content

Commit c5f3319

Browse files
raymasiclatclaude
andcommitted
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/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- Gemfile.rails-7.0-stable
1818
- Gemfile.rails-7.2-stable
1919
- Gemfile.rails-8.0-stable
20+
- Gemfile.rails-8.1-stable
2021
ruby-version: ['3.0', '3.1', '3.2', '3.3']
2122
exclude:
2223
# Rails 7.2 doesn't work with Ruby 3.0 (requires Ruby 3.1+)
@@ -27,6 +28,11 @@ jobs:
2728
ruby-version: '3.0'
2829
- gemfile: Gemfile.rails-8.0-stable
2930
ruby-version: '3.1'
31+
# Rails 8.1 requires Ruby 3.2+
32+
- gemfile: Gemfile.rails-8.1-stable
33+
ruby-version: '3.0'
34+
- gemfile: Gemfile.rails-8.1-stable
35+
ruby-version: '3.1'
3036
env:
3137
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
3238
steps:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v3.5.0 (2026-04-30)
4+
5+
### Added
6+
7+
- Add Rails 8.1 compatibility. Rails 8.1 changed `PredicateBuilder::PolymorphicArrayValue#initialize` from `(associated_table, values)` to `(reflection, values)`, dropping the `@associated_table` ivar. `type_to_ids_mapping` now reads `@reflection` when available and falls back to `@associated_table.send(:reflection)` for older Rails versions.
8+
39
## v3.2.1 (2023-12-14)
410

511
### Fixed

gemfiles/Gemfile.rails-8.1-stable

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gemspec path: ".."
6+
7+
gem "activerecord", github: "rails/rails", branch: "8-1-stable"

lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ module PolymorphicArrayValueExtension
1010
# end
1111

1212
def type_to_ids_mapping
13-
association = @associated_table.send(:reflection)
13+
# Rails 8.1 changed `PredicateBuilder::PolymorphicArrayValue#initialize`
14+
# from `(associated_table, values)` to `(reflection, values)`, dropping
15+
# the `@associated_table` ivar. Read whichever ivar is available so this
16+
# gem works across Rails 6.1–8.1.
17+
association = if instance_variable_defined?(:@reflection) && @reflection
18+
@reflection
19+
else
20+
@associated_table.send(:reflection)
21+
end
1422

1523
name = association.name
1624
default_hash = Hash.new { |hsh, key| hsh[key] = [] }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module PolymorphicIntegerType
4-
VERSION = '3.4.0'
4+
VERSION = '3.5.0'
55
end

0 commit comments

Comments
 (0)