diff --git a/lib/arjdbc/abstract/relation_query_attribute_monkey_patch.rb b/lib/arjdbc/abstract/relation_query_attribute_monkey_patch.rb new file mode 100644 index 000000000..3eabbc71d --- /dev/null +++ b/lib/arjdbc/abstract/relation_query_attribute_monkey_patch.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require "active_model/attribute" + +module ActiveRecord + # NOTE: improved implementation for hash methods that is used to + # compare objects. AR and arel commonly use `[a, b] - [b]` operations and + # JRuby internally uses the hash method to implement that operation, + # on the other hand, CRuby does not use the hash method + # for small arrays (length <= 16). + class Relation + # monkey patch + module RelationQueryAttributeMonkeyPatch + def hash + # [self.class, name, value_for_database, type].hash + [self.class, name, value_before_type_cast, type].hash + end + end + + class QueryAttribute + prepend RelationQueryAttributeMonkeyPatch + end + end +end diff --git a/lib/arjdbc/mysql/adapter.rb b/lib/arjdbc/mysql/adapter.rb index 1bf6ce612..b45b254ae 100644 --- a/lib/arjdbc/mysql/adapter.rb +++ b/lib/arjdbc/mysql/adapter.rb @@ -11,6 +11,8 @@ require 'arjdbc/abstract/statement_cache' require 'arjdbc/abstract/transaction_support' +require "arjdbc/abstract/relation_query_attribute_monkey_patch" + module ActiveRecord module ConnectionAdapters AbstractMysqlAdapter.class_eval do diff --git a/lib/arjdbc/postgresql/adapter.rb b/lib/arjdbc/postgresql/adapter.rb index 6c24393ca..d83d36d07 100644 --- a/lib/arjdbc/postgresql/adapter.rb +++ b/lib/arjdbc/postgresql/adapter.rb @@ -27,6 +27,8 @@ require 'active_model' +require "arjdbc/abstract/relation_query_attribute_monkey_patch" + module ArJdbc # Strives to provide Rails built-in PostgreSQL adapter (API) compatibility. module PostgreSQL diff --git a/lib/arjdbc/sqlite3/adapter.rb b/lib/arjdbc/sqlite3/adapter.rb index 913eb5dac..407e22017 100644 --- a/lib/arjdbc/sqlite3/adapter.rb +++ b/lib/arjdbc/sqlite3/adapter.rb @@ -18,6 +18,8 @@ require "active_support/core_ext/class/attribute" require "arjdbc/sqlite3/column" +require "arjdbc/abstract/relation_query_attribute_monkey_patch" + module SQLite3 module Constants module Open