Skip to content

Commit

Permalink
Reintroduce visit_Arel_Nodes_HomogeneousIn monkey-patch
Browse files Browse the repository at this point in the history
Method was incorrectly removed in #1068
  • Loading branch information
aidanharan committed Nov 13, 2023
1 parent 9dc8d7a commit b357cde
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/arel/visitors/sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,38 @@ def visit_Arel_Nodes_Grouping(o, collector)
super
end

def visit_Arel_Nodes_HomogeneousIn(o, collector)
collector.preparable = false

collector = visit o.left, collector

if o.type == :in
collector << " IN ("
else
collector << " NOT IN ("
end

values = o.casted_values

if values.empty?
collector << @connection.quote(nil)
elsif @connection.prepared_statements
# Monkey-patch start. Add query attribute bindings rather than just values.
column_name = o.attribute.name
column_type = o.attribute.relation.type_for_attribute(column_name)
# Use cast_type on encrypted attributes. Don't encrypt them again
column_type = column_type.cast_type if column_type.is_a?(ActiveRecord::Encryption::EncryptedAttributeType)
attrs = values.map { |value| ActiveRecord::Relation::QueryAttribute.new(column_name, value, column_type) }

collector.add_binds(attrs, &bind_block)
# Monkey-patch end.
else
collector.add_binds(values, &bind_block)
end

collector << ")"
end

def visit_Arel_Nodes_SelectStatement(o, collector)
@select_statement = o
distinct_One_As_One_Is_So_Not_Fetch o
Expand Down

0 comments on commit b357cde

Please sign in to comment.