Skip to content

Commit fd6c2d7

Browse files
authored
Merge pull request #981 from yellowspot/support-encrypted-attributes
[Rails 7] Support find_by an encrypted attribute
2 parents 420def7 + bd046bd commit fd6c2d7

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
#### Added
1212

1313
- [#972](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/972) Support `ActiveRecord::QueryLogs`
14+
- [#981](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/981) Support `find_by` an encrypted attribute
1415

1516
Please check [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/6-1-stable/CHANGELOG.md) for previous changes.

lib/arel/visitors/sqlserver.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def visit_Arel_Nodes_HomogeneousIn(o, collector)
8383
# Monkey-patch start. Add query attribute bindings rather than just values.
8484
column_name = o.column_name
8585
column_type = o.attribute.relation.type_for_attribute(o.column_name)
86+
# Use cast_type on encrypted attributes. Don't encrypt them again
87+
column_type = column_type.cast_type if column_type.is_a?(ActiveRecord::Encryption::EncryptedAttributeType)
8688
attrs = values.map { |value| ActiveRecord::Relation::QueryAttribute.new(column_name, value, column_type) }
8789

8890
collector.add_binds(attrs, &bind_block)

0 commit comments

Comments
 (0)