From 34873a9c6e32c93941c5c1eaf5cdd1a1f9132a1c Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Mon, 7 Oct 2024 16:33:49 -0400 Subject: [PATCH 1/3] Arel::Table changes in rails 7.1 Rails 7.1 removed the table_name alias to name so just use name: See: https://www.github.com/rails/rails/pull/46864 Rails 7.1 removed the writer for the table_alias so set the instance variable. We will need to see if there is a way to do this that's less brittle. See: https://www.github.com/rails/rails/pull/48927 --- lib/active_record/virtual_attributes/virtual_delegates.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_record/virtual_attributes/virtual_delegates.rb b/lib/active_record/virtual_attributes/virtual_delegates.rb index a439110c..7fd12b2d 100644 --- a/lib/active_record/virtual_attributes/virtual_delegates.rb +++ b/lib/active_record/virtual_attributes/virtual_delegates.rb @@ -271,11 +271,11 @@ def self.select_from_alias(to_ref, col, to_model_col_name, src_model_id) def self.select_from_alias_table(to_klass, src_relation) to_table = to_klass.arel_table # if a self join, alias the second table to a different name - if to_table.table_name == src_relation.table_name + if to_table.name == src_relation.name # use a dup to not modify the primary table in the model to_table = to_table.dup # use a table alias to not conflict with table name in the primary query - to_table.table_alias = "#{to_table.table_name}_sub" + to_table.instance_variable_set(:@table_alias, "#{to_table.name}_sub") end to_table end From 978de6ee77f363fb86a87d964f2699977b52c860 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Mon, 17 Feb 2025 10:52:42 -0500 Subject: [PATCH 2/3] Master supports rails 7.1, drop ruby 2.7-3.0, add 3.2-3.4 --- .github/workflows/ci.yaml | 5 +++-- Gemfile | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5cc5d3da..3ed5d25a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,9 +12,10 @@ jobs: strategy: matrix: ruby-version: - - '2.7' - - '3.0' - '3.1' + - '3.2' + - '3.3' + - '3.4' services: postgres: image: postgres:13 diff --git a/Gemfile b/Gemfile index 49ec9d52..918dd023 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "activerecord", "~>7.0.8" +gem "activerecord", "~>7.1.5" gem "mysql2" gem "pg" gem "sqlite3", "< 2" From defbba05c677075960f132fbdbd9ba4a38ad8b43 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Tue, 18 Feb 2025 13:57:31 -0500 Subject: [PATCH 3/3] Use a public API to set the table alias Since they dropped the table_alias writer on the Arel::Table, we're no longer modifying it so we can drop the dup. --- lib/active_record/virtual_attributes/virtual_delegates.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/active_record/virtual_attributes/virtual_delegates.rb b/lib/active_record/virtual_attributes/virtual_delegates.rb index 7fd12b2d..6de2d0c0 100644 --- a/lib/active_record/virtual_attributes/virtual_delegates.rb +++ b/lib/active_record/virtual_attributes/virtual_delegates.rb @@ -272,10 +272,8 @@ def self.select_from_alias_table(to_klass, src_relation) to_table = to_klass.arel_table # if a self join, alias the second table to a different name if to_table.name == src_relation.name - # use a dup to not modify the primary table in the model - to_table = to_table.dup # use a table alias to not conflict with table name in the primary query - to_table.instance_variable_set(:@table_alias, "#{to_table.name}_sub") + to_table = to_table.alias("#{to_table.name}_sub") end to_table end