aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@squareup.com>2014-09-13 19:35:34 -0700
committerTamir Duberstein <tamird@squareup.com>2014-09-13 20:04:34 -0700
commit8c73dad0761980061ce45018172034cad34cd585 (patch)
tree12f140e8dcece55f591591f6da95d15b17db0780 /lib/arel
parentd23df0ec8a50b50024f8d4dc5d91a47509df9b1f (diff)
downloadrails-8c73dad0761980061ce45018172034cad34cd585.tar.gz
rails-8c73dad0761980061ce45018172034cad34cd585.tar.bz2
rails-8c73dad0761980061ce45018172034cad34cd585.zip
`Extract#as` should not mutate the receiver
Fixes https://github.com/rails/rails/issues/16913
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/nodes/extract.rb13
-rw-r--r--lib/arel/visitors/to_sql.rb9
2 files changed, 4 insertions, 18 deletions
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