Skip to content

Commit

Permalink
Use safety operator when checking if connection is SQL Server
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Oct 10, 2023
1 parent d1a3b1d commit 0c66077
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module SQLServerTransaction
private

def sqlserver?
connection.respond_to?(:sqlserver?) && connection.sqlserver?
connection&.sqlserver?
end

def current_isolation_level
Expand Down
2 changes: 1 addition & 1 deletion lib/arel/visitors/sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0c66077

Please sign in to comment.