Skip to content

Commit 377f6f6

Browse files
Merge pull request rails#49050 from JohnAnon9771/fix/issue-48535
[Fix rails#48535]: fix behavior of `proc_for_binds` in `Arel::Nodes::HomogenousIn`
2 parents a409c63 + fb5773b commit 377f6f6

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

activerecord/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Fix `where(field: values)` queries when `field` is a serialized attribute
2+
(for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
3+
column).
4+
5+
*João Alves*
6+
17
* Make the output of `ActiveRecord::Core#inspect` configurable.
28

39
By default, calling `inspect` on a record will yield a formatted string including just the `id`.

activerecord/lib/active_record/encryption/extended_deterministic_queries.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def self.install_support
2828
ActiveRecord::Relation.prepend(RelationQueries)
2929
ActiveRecord::Base.include(CoreQueries)
3030
ActiveRecord::Encryption::EncryptedAttributeType.prepend(ExtendedEncryptableType)
31-
Arel::Nodes::HomogeneousIn.prepend(InWithAdditionalValues)
3231
end
3332

3433
# When modifying this file run performance tests in
@@ -153,20 +152,6 @@ def serialize(data)
153152
end
154153
end
155154
end
156-
157-
module InWithAdditionalValues
158-
def proc_for_binds
159-
-> value { ActiveModel::Attribute.with_cast_value(attribute.name, value, encryption_aware_type_caster) }
160-
end
161-
162-
def encryption_aware_type_caster
163-
if attribute.type_caster.is_a?(ActiveRecord::Encryption::EncryptedAttributeType)
164-
attribute.type_caster.cast_type
165-
else
166-
attribute.type_caster
167-
end
168-
end
169-
end
170155
end
171156
end
172157
end

activerecord/lib/arel/nodes/homogeneous_in.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def casted_values
4848
end
4949

5050
def proc_for_binds
51-
-> value { ActiveModel::Attribute.with_cast_value(attribute.name, value, attribute.type_caster) }
51+
-> value { ActiveModel::Attribute.with_cast_value(attribute.name, value, ActiveModel::Type.default_value) }
5252
end
5353

5454
def fetch_attribute(&block)

activerecord/test/cases/serialized_attribute_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def test_where_by_serialized_attribute_with_hash_in_array
245245
settings = { "color" => "green" }
246246
Topic.serialize(:content, type: Hash)
247247
topic = Topic.create!(content: settings)
248-
assert_equal topic, Topic.where(content: [settings]).take
248+
assert_equal topic, Topic.where(content: [settings, { "herring" => "red" }]).take
249249
end
250250

251251
def test_serialized_default_class

0 commit comments

Comments
 (0)