Skip to content

Commit 5b63b6b

Browse files
committed
fix in the with clause for ar 7.1
1 parent fb548b8 commit 5b63b6b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/core_extensions/active_record/relation/query_methods.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,27 @@ def reverse_order!
1212
self
1313
end
1414

15+
def build_with_value_from_hash(hash)
16+
return super if ::ActiveRecord::version >= Gem::Version.new('7.2')
17+
18+
# Redefine for ActiveRecord < 7.2
19+
hash.map do |name, value|
20+
expression =
21+
case value
22+
when ::Arel::Nodes::SqlLiteral then ::Arel::Nodes::Grouping.new(value)
23+
when ::ActiveRecord::Relation then value.arel
24+
when ::Arel::SelectManager then value
25+
when Symbol then value
26+
else
27+
raise ArgumentError, "Unsupported argument type: `#{value}` #{value.class}"
28+
end
29+
::Arel::Nodes::TableAlias.new(expression, name)
30+
end
31+
end
32+
1533
def build_with_expression_from_value(value, nested = false)
1634
case value
17-
when Symbol
18-
value
35+
when Symbol then value
1936
else
2037
super
2138
end

0 commit comments

Comments
 (0)