Skip to content

Commit f3763e6

Browse files
committed
Remove SqlLiteral re-wrapping from Arel.sql
Previously, passing a SqlLiteral to Arel.sql would wrap the SqlLiteral in a new SqlLiteral (which is generally unnecessary since it allocates a new SqlLiteral/String). This commit updates Arel.sql to no longer perform the wrapping of the given "sql_string" is already a SqlLiteral.
1 parent a2928dd commit f3763e6

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

activerecord/lib/active_record/relation/query_methods.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,11 +1624,7 @@ def build_where_clause(opts, rest = []) # :nodoc:
16241624
case opts
16251625
when String
16261626
if rest.empty?
1627-
if Arel.arel_node?(opts)
1628-
parts = [opts]
1629-
else
1630-
parts = [Arel.sql(opts)]
1631-
end
1627+
parts = [Arel.sql(opts)]
16321628
elsif rest.first.is_a?(Hash) && /:\w+/.match?(opts)
16331629
parts = [build_named_bound_sql_literal(opts, rest.first)]
16341630
elsif opts.include?("?")

activerecord/lib/arel.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ module Arel
5050
# Use this option only if the SQL is idempotent, as it could be executed
5151
# more than once.
5252
def self.sql(sql_string, *positional_binds, retryable: false, **named_binds)
53-
if positional_binds.empty? && named_binds.empty?
53+
if Arel::Nodes::SqlLiteral === sql_string
54+
sql_string
55+
elsif positional_binds.empty? && named_binds.empty?
5456
Arel::Nodes::SqlLiteral.new(sql_string, retryable: retryable)
5557
else
5658
Arel::Nodes::BoundSqlLiteral.new sql_string, positional_binds, named_binds

0 commit comments

Comments
 (0)