Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- Gemfile.rails-7.0-stable
- Gemfile.rails-7.2-stable
- Gemfile.rails-8.0-stable
- Gemfile.rails-8.1-stable
ruby-version: ['3.0', '3.1', '3.2', '3.3']
exclude:
# Rails 7.2 doesn't work with Ruby 3.0 (requires Ruby 3.1+)
Expand All @@ -27,6 +28,11 @@ jobs:
ruby-version: '3.0'
- gemfile: Gemfile.rails-8.0-stable
ruby-version: '3.1'
# Rails 8.1 requires Ruby 3.2+
- gemfile: Gemfile.rails-8.1-stable
ruby-version: '3.0'
- gemfile: Gemfile.rails-8.1-stable
ruby-version: '3.1'
env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
steps:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v3.5.0 (2026-04-30)

### Added

- 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.

## v3.2.1 (2023-12-14)

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions gemfiles/Gemfile.rails-8.1-stable
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec path: ".."

gem "activerecord", github: "rails/rails", branch: "8-1-stable"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ module PolymorphicArrayValueExtension
# end

def type_to_ids_mapping
association = @associated_table.send(:reflection)
# Rails 8.1 changed `PredicateBuilder::PolymorphicArrayValue#initialize`
# from `(associated_table, values)` to `(reflection, values)`, dropping
# the `@associated_table` ivar. Read whichever ivar is available so this
# gem works across Rails 6.1–8.1.
association = if instance_variable_defined?(:@reflection) && @reflection
@reflection
else
@associated_table.send(:reflection)
end

name = association.name
default_hash = Hash.new { |hsh, key| hsh[key] = [] }
Expand Down
2 changes: 1 addition & 1 deletion lib/polymorphic_integer_type/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module PolymorphicIntegerType
VERSION = '3.4.0'
VERSION = '3.5.0'
end
5 changes: 5 additions & 0 deletions spec/polymorphic_integer_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
expect(Link.where(source: [source])).to eq [link]
end

it "properly finds objects when passing an array of mixed-type sources" do
link_for_dog = Link.create(source: dog)
expect(Link.where(source: [cat, dog])).to match_array [link, link_for_dog]
end

it "properly finds the object with a find_by" do
expect(Link.find_by(source: source, id: link.id)).to eql link
end
Expand Down
Loading