Skip to content

Commit 2a60a21

Browse files
authored
Fix serialized encrypted attributes (#1218)
1 parent b59f40d commit 2a60a21

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,13 @@ def sp_executesql_types_and_parameters(binds)
321321

322322
def sp_executesql_sql_type(attr)
323323
if attr.respond_to?(:type)
324-
return attr.type.sqlserver_type if attr.type.respond_to?(:sqlserver_type)
324+
type = attr.type.is_a?(ActiveRecord::Normalization::NormalizedValueType) ? attr.type.cast_type : attr.type
325+
type = type.subtype if type.serialized?
325326

326-
if attr.type.is_a?(ActiveRecord::Encryption::EncryptedAttributeType) && attr.type.instance_variable_get(:@cast_type).respond_to?(:sqlserver_type)
327-
return attr.type.instance_variable_get(:@cast_type).sqlserver_type
327+
return type.sqlserver_type if type.respond_to?(:sqlserver_type)
328+
329+
if type.is_a?(ActiveRecord::Encryption::EncryptedAttributeType) && type.instance_variable_get(:@cast_type).respond_to?(:sqlserver_type)
330+
return type.instance_variable_get(:@cast_type).sqlserver_type
328331
end
329332
end
330333

0 commit comments

Comments
 (0)