Skip to content

Commit 63d435e

Browse files
authored
Merge pull request rails#47158 from benedikt/arel-symbol-aliases
Allow passing Symbols as aliases in Arel
2 parents aa01e3c + ceae0d2 commit 63d435e

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)