-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monkey patch active record relation query attribute hash method to be…
…tter compare objects This a important since arel and AR commonly use array - operator
- Loading branch information
1 parent
44e7775
commit 10eb984
Showing
4 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
lib/arjdbc/abstract/relation_query_attribute_monkey_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 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 | ||
private | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters