Skip to content
Open
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
5 changes: 3 additions & 2 deletions lib/active_record/tenanted/patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def with_temporary_pool(db_config, clobber: false)
end
end

# TODO: This monkey patch shouldn't be necessary after 8.1 lands and the need for a
# connection is removed. For details see https://github.com/rails/rails/pull/54348
# This patch is only applied for Rails 8.1.x. Rails 8.2+ removed the with_connection
# call in _default_attributes (rails/rails#54333), making this patch unnecessary.
# See railtie.rb for the version check.
module Attributes
extend ActiveSupport::Concern

Expand Down
6 changes: 5 additions & 1 deletion lib/active_record/tenanted/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ class Railtie < ::Rails::Railtie

initializer "active_record_tenanted.monkey_patches" do
ActiveSupport.on_load(:active_record) do
prepend ActiveRecord::Tenanted::Patches::Attributes
# Rails 8.2+ removed the with_connection call in _default_attributes (rails/rails#54333),
# so this patch is only needed for Rails 8.1.x
if ActiveRecord.version < Gem::Version.new("8.2.0.alpha")
prepend ActiveRecord::Tenanted::Patches::Attributes
end
ActiveRecord::Tasks::DatabaseTasks.prepend ActiveRecord::Tenanted::Patches::DatabaseTasks
end
end
Expand Down