From 8c73dad0761980061ce45018172034cad34cd585 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sat, 13 Sep 2014 19:35:34 -0700 Subject: `Extract#as` should not mutate the receiver Fixes https://github.com/rails/rails/issues/16913 --- lib/arel/nodes/extract.rb | 13 +++---------- lib/arel/visitors/to_sql.rb | 9 +-------- 2 files changed, 4 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/arel/nodes/extract.rb b/lib/arel/nodes/extract.rb index 64f5c3ff0f..7c69deadef 100644 --- a/lib/arel/nodes/extract.rb +++ b/lib/arel/nodes/extract.rb @@ -1,20 +1,14 @@ module Arel module Nodes class Extract < Arel::Nodes::Unary + include Arel::AliasPredication include Arel::Predications attr_accessor :field - attr_accessor :alias - def initialize expr, field, aliaz = nil + def initialize expr, field super(expr) @field = field - @alias = aliaz && SqlLiteral.new(aliaz) - end - - def as aliaz - self.alias = SqlLiteral.new(aliaz) - self end def hash @@ -23,8 +17,7 @@ module Arel def eql? other super && - self.field == other.field && - self.alias == other.alias + self.field == other.field end alias :== :eql? end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index ae1b7930af..ca09373b64 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -475,14 +475,7 @@ module Arel def visit_Arel_Nodes_Extract o, collector collector << "EXTRACT(#{o.field.to_s.upcase} FROM " - collector = visit o.expr, collector - collector << ")" - if o.alias - collector << " AS " - visit o.alias, collector - else - collector - end + visit(o.expr, collector) << ")" end def visit_Arel_Nodes_Count o, collector -- cgit v1.2.3