Skip to content

Apply monkey es for SQL Server connections only #933

New issue

Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.

By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on ? Sign in to your account

Merged
Merged
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
##

#### Fixed

- [#933](https://.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/933) Conditionally apply SQL Server monkey es to ActiveRecord so that it is safe to use this gem alongside other database adapters (e.g. PostgreSQL) in a multi-database Rails app

#### Changed

- ...

#### Added

- ...

## v6.1.0.0

- No changes
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,8 @@ module AttributeMethods
private

def attributes_for_update(attribute_names)
return super unless self.class.connection.adapter_name == "SQLServer"

super.reject do |name|
column = self.class.columns_hash[name]
column && column.respond_to?(:is_identity?) && column.is_identity?
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,8 @@ module CoreExt
module Calculations
# Same as original except we don't perform PostgreSQL hack that removes ordering.
def calculate(operation, column_name)
return super unless klass.connection.adapter_name == "SQLServer"

if has_include?(column_name)
relation = apply_join_dependency

Expand All@@ -29,6 +31,8 @@ def calculate(operation, column_name)
private

def build_count_subquery(relation, column_name, distinct)
return super unless klass.connection.adapter_name == "SQLServer"

super(relation.unscope(:order), column_name, distinct)
end
end
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,8 @@ module Explain
SQLSERVER_STATEMENT_REGEXP = /N'(.+)', N'(.+)', (.+)/

def exec_explain(queries)
return super unless connection.adapter_name == "SQLServer"

unprepared_queries = queries.map do |(sql, binds)|
[unprepare_sqlserver_statement(sql, binds), binds]
end
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ module FinderMethods

# Same as original except we order by values in distinct select if present.
def construct_relation_for_exists(conditions)
return super unless klass.connection.adapter_name == "SQLServer"

conditions = sanitize_forbidden_attributes(conditions)

if distinct_value && offset_value
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,8 @@ module Preloader
private

def records_for(ids)
return super unless klass.connection.adapter_name == "SQLServer"

ids.each_slice(in_clause_length).flat_map do |slice|
scope.where(association_key_name => slice).load do |record|
# Processing only the first owner
Expand Down