Skip to content

Commit d1409cc

Browse files
committed
Avoid using try to handle radically different types
It's less error prone to be more deliberate about casting.
1 parent c975ec2 commit d1409cc

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

activerecord/lib/active_record/relation/query_methods.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,15 +1910,19 @@ def build_with_value_from_hash(hash)
19101910
end
19111911
end
19121912

1913-
def build_with_expression_from_value(value)
1913+
def build_with_expression_from_value(value, nested = false)
19141914
case value
19151915
when Arel::Nodes::SqlLiteral then Arel::Nodes::Grouping.new(value)
1916-
when ActiveRecord::Relation then value.arel
1916+
when ActiveRecord::Relation
1917+
if nested
1918+
value.arel.ast
1919+
else
1920+
value.arel
1921+
end
19171922
when Arel::SelectManager then value
19181923
when Array
19191924
parts = value.map do |query|
1920-
with_expression = build_with_expression_from_value(query)
1921-
with_expression.try(:ast) || with_expression
1925+
build_with_expression_from_value(query, true)
19221926
end
19231927

19241928
parts.reduce do |result, value|

0 commit comments

Comments
 (0)