From 3b600a3fb686d5872a56a895ffbfc4844a13e5e1 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Wed, 16 Oct 2019 20:38:19 -0400 Subject: [PATCH] Use the model's adapter for the attribute type lookup --- activerecord/lib/active_record/attributes.rb | 3 ++- activerecord/lib/active_record/type.rb | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb index c7846dbe7a..dc3cfed88f 100644 --- a/activerecord/lib/active_record/attributes.rb +++ b/activerecord/lib/active_record/attributes.rb @@ -247,7 +247,8 @@ module ActiveRecord super attributes_to_define_after_schema_loads.each do |name, (type, options)| if type.is_a?(Symbol) - type = ActiveRecord::Type.lookup(type, **options.except(:default)) + adapter_name = ActiveRecord::Type.adapter_name_from(self) + type = ActiveRecord::Type.lookup(type, **options.except(:default), adapter: adapter_name) end define_attribute(name, type, **options.slice(:default)) diff --git a/activerecord/lib/active_record/type.rb b/activerecord/lib/active_record/type.rb index 4c1ef1a7e4..52d72a4320 100644 --- a/activerecord/lib/active_record/type.rb +++ b/activerecord/lib/active_record/type.rb @@ -46,9 +46,14 @@ module ActiveRecord @default_value ||= Value.new end + def adapter_name_from(model) # :nodoc: + # TODO: this shouldn't depend on a connection to the database + model.connection.adapter_name.downcase.to_sym + end + private def current_adapter_name - ActiveRecord::Base.connection.adapter_name.downcase.to_sym + adapter_name_from(ActiveRecord::Base) end end