From 0c66077529f63d534eb150fc496751c429ff9921 Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Tue, 10 Oct 2023 11:44:01 +0100 Subject: [PATCH] Use safety operator when checking if connection is SQL Server --- .../connection_adapters/sqlserver/core_ext/calculations.rb | 2 +- .../connection_adapters/sqlserver/core_ext/finder_methods.rb | 2 +- .../connection_adapters/sqlserver/core_ext/preloader.rb | 2 +- lib/active_record/connection_adapters/sqlserver/transaction.rb | 2 +- lib/arel/visitors/sqlserver.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb b/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb index 34355ef53..8007f09f6 100644 --- a/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +++ b/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb @@ -9,7 +9,7 @@ module SQLServer module CoreExt module Calculations def calculate(operation, column_name) - if klass.connection.sqlserver? + if klass.connection&.sqlserver? _calculate(operation, column_name) else super diff --git a/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb b/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb index fe9271508..8c077ee03 100644 --- a/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +++ b/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb @@ -11,7 +11,7 @@ module FinderMethods private def construct_relation_for_exists(conditions) - if klass.connection.sqlserver? + if klass.connection&.sqlserver? _construct_relation_for_exists(conditions) else super diff --git a/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb b/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb index db258bd7e..9c658aa1e 100644 --- a/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb +++ b/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb @@ -8,7 +8,7 @@ module SQLServer module CoreExt module LoaderQuery def load_records_for_keys(keys, &block) - return super unless scope.connection.sqlserver? + return super unless scope.connection&.sqlserver? if association_key_name.is_a?(Array) query_constraints = Hash.new { |hsh, key| hsh[key] = Set.new } diff --git a/lib/active_record/connection_adapters/sqlserver/transaction.rb b/lib/active_record/connection_adapters/sqlserver/transaction.rb index 86f4aa777..b7dd2668c 100644 --- a/lib/active_record/connection_adapters/sqlserver/transaction.rb +++ b/lib/active_record/connection_adapters/sqlserver/transaction.rb @@ -8,7 +8,7 @@ module SQLServerTransaction private def sqlserver? - connection.respond_to?(:sqlserver?) && connection.sqlserver? + connection&.sqlserver? end def current_isolation_level diff --git a/lib/arel/visitors/sqlserver.rb b/lib/arel/visitors/sqlserver.rb index 74019cc9a..a3bbd4501 100644 --- a/lib/arel/visitors/sqlserver.rb +++ b/lib/arel/visitors/sqlserver.rb @@ -97,7 +97,7 @@ def visit_Arel_Table(o, collector) # github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/450 table_name = begin - if o.class.engine.connection.respond_to?(:sqlserver?) && o.class.engine.connection.database_prefix_remote_server? + if o.class.engine.connection&.sqlserver? && o.class.engine.connection.database_prefix_remote_server? remote_server_table_name(o) else quote_table_name(o.name)