Skip to content

Commit ceae0d2

Browse files
benediktkamipo
authored andcommitted
Allow passing Symbols as aliases in Arel
Table names, column names, and table aliases all allow symbols. This brings back symbol support for `#as` on nodes for consistency with these other methods.
1 parent aa01e3c commit ceae0d2

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

activerecord/lib/arel/alias_predication.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module Arel # :nodoc: all
44
module AliasPredication
55
def as(other)
6+
other = other.name if other.is_a?(Symbol)
7+
68
Nodes::As.new self, Nodes::SqlLiteral.new(other, retryable: true)
79
end
810
end

activerecord/test/cases/arel/nodes/as_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ module Nodes
1818
as = attr.as("foo")
1919
assert_kind_of Arel::Nodes::SqlLiteral, as.right
2020
end
21+
22+
it "converts right to SqlLiteral if a symbol" do
23+
attr = Table.new(:users)[:id]
24+
as = attr.as(:foo)
25+
assert_kind_of Arel::Nodes::SqlLiteral, as.right
26+
end
2127
end
2228

2329
describe "equality" do

0 commit comments

Comments
 (0)