mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Change the interface of having
to match that of where
These two clauses have nearly identical semantics with regards to how they would be constructed as an AST. It doesn't make sense for their interfaces to be separate.
This commit is contained in:
parent
d36a769234
commit
aac9da257f
10 changed files with 29 additions and 29 deletions
|
@ -2,7 +2,7 @@ module Arel
|
|||
module Nodes
|
||||
class SelectCore < Arel::Nodes::Node
|
||||
attr_accessor :top, :projections, :wheres, :groups, :windows
|
||||
attr_accessor :having, :source, :set_quantifier
|
||||
attr_accessor :havings, :source, :set_quantifier
|
||||
|
||||
def initialize
|
||||
super()
|
||||
|
@ -14,7 +14,7 @@ module Arel
|
|||
@projections = []
|
||||
@wheres = []
|
||||
@groups = []
|
||||
@having = nil
|
||||
@havings = []
|
||||
@windows = []
|
||||
end
|
||||
|
||||
|
@ -35,14 +35,14 @@ module Arel
|
|||
@projections = @projections.clone
|
||||
@wheres = @wheres.clone
|
||||
@groups = @groups.clone
|
||||
@having = @having.clone if @having
|
||||
@havings = @havings.clone
|
||||
@windows = @windows.clone
|
||||
end
|
||||
|
||||
def hash
|
||||
[
|
||||
@source, @top, @set_quantifier, @projections,
|
||||
@wheres, @groups, @having, @windows
|
||||
@wheres, @groups, @havings, @windows
|
||||
].hash
|
||||
end
|
||||
|
||||
|
@ -54,7 +54,7 @@ module Arel
|
|||
self.projections == other.projections &&
|
||||
self.wheres == other.wheres &&
|
||||
self.groups == other.groups &&
|
||||
self.having == other.having &&
|
||||
self.havings == other.havings &&
|
||||
self.windows == other.windows
|
||||
end
|
||||
alias :== :eql?
|
||||
|
|
|
@ -23,7 +23,6 @@ module Arel
|
|||
%w{
|
||||
Bin
|
||||
Group
|
||||
Having
|
||||
Limit
|
||||
Not
|
||||
Offset
|
||||
|
|
|
@ -118,8 +118,8 @@ module Arel
|
|||
join(relation, Nodes::OuterJoin)
|
||||
end
|
||||
|
||||
def having *exprs
|
||||
@ctx.having = Nodes::Having.new(collapse(exprs, @ctx.having))
|
||||
def having expr
|
||||
@ctx.havings << expr
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ module Arel
|
|||
visit o.wheres
|
||||
visit o.groups
|
||||
visit o.windows
|
||||
visit o.having
|
||||
visit o.havings
|
||||
end
|
||||
|
||||
def visit_Arel_Nodes_SelectStatement o
|
||||
|
|
|
@ -34,8 +34,13 @@ module Arel
|
|||
collector = inject_join o.groups, collector, ", "
|
||||
end
|
||||
|
||||
maybe_visit o.having, collector
|
||||
if o.havings.any?
|
||||
collector << " HAVING "
|
||||
collector = inject_join o.havings, collector, " AND "
|
||||
end
|
||||
collector
|
||||
end
|
||||
|
||||
def visit_Arel_Nodes_Offset o, collector
|
||||
collector << "SKIP "
|
||||
visit o.expr, collector
|
||||
|
|
|
@ -265,7 +265,10 @@ module Arel
|
|||
end
|
||||
end
|
||||
|
||||
collector = maybe_visit o.having, collector
|
||||
unless o.havings.empty?
|
||||
collector << " HAVING "
|
||||
inject_join o.havings, collector, AND
|
||||
end
|
||||
|
||||
unless o.windows.empty?
|
||||
collector << WINDOW
|
||||
|
@ -404,11 +407,6 @@ module Arel
|
|||
end
|
||||
end
|
||||
|
||||
def visit_Arel_Nodes_Having o, collector
|
||||
collector << "HAVING "
|
||||
visit o.expr, collector
|
||||
end
|
||||
|
||||
def visit_Arel_Nodes_Offset o, collector
|
||||
collector << "OFFSET "
|
||||
visit o.expr, collector
|
||||
|
|
|
@ -34,14 +34,14 @@ module Arel
|
|||
core1.wheres = %w[g h i]
|
||||
core1.groups = %w[j k l]
|
||||
core1.windows = %w[m n o]
|
||||
core1.having = %w[p q r]
|
||||
core1.havings = %w[p q r]
|
||||
core2 = SelectCore.new
|
||||
core2.froms = %w[a b c]
|
||||
core2.projections = %w[d e f]
|
||||
core2.wheres = %w[g h i]
|
||||
core2.groups = %w[j k l]
|
||||
core2.windows = %w[m n o]
|
||||
core2.having = %w[p q r]
|
||||
core2.havings = %w[p q r]
|
||||
array = [core1, core2]
|
||||
assert_equal 1, array.uniq.size
|
||||
end
|
||||
|
@ -53,14 +53,14 @@ module Arel
|
|||
core1.wheres = %w[g h i]
|
||||
core1.groups = %w[j k l]
|
||||
core1.windows = %w[m n o]
|
||||
core1.having = %w[p q r]
|
||||
core1.havings = %w[p q r]
|
||||
core2 = SelectCore.new
|
||||
core2.froms = %w[a b c]
|
||||
core2.projections = %w[d e f]
|
||||
core2.wheres = %w[g h i]
|
||||
core2.groups = %w[j k l]
|
||||
core2.windows = %w[m n o]
|
||||
core2.having = %w[l o l]
|
||||
core2.havings = %w[l o l]
|
||||
array = [core1, core2]
|
||||
assert_equal 2, array.uniq.size
|
||||
end
|
||||
|
|
|
@ -111,22 +111,22 @@ module Arel
|
|||
it 'converts strings to SQLLiterals' do
|
||||
table = Table.new :users
|
||||
mgr = table.from
|
||||
mgr.having 'foo'
|
||||
mgr.having Arel.sql('foo')
|
||||
mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo }
|
||||
end
|
||||
|
||||
it 'can have multiple items specified separately' do
|
||||
table = Table.new :users
|
||||
mgr = table.from
|
||||
mgr.having 'foo'
|
||||
mgr.having 'bar'
|
||||
mgr.having Arel.sql('foo')
|
||||
mgr.having Arel.sql('bar')
|
||||
mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo AND bar }
|
||||
end
|
||||
|
||||
it 'can have multiple items specified together' do
|
||||
it 'can receive any node' do
|
||||
table = Table.new :users
|
||||
mgr = table.from
|
||||
mgr.having 'foo', 'bar'
|
||||
mgr.having Arel::Nodes::And.new([Arel.sql('foo'), Arel.sql('bar')])
|
||||
mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo AND bar }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,7 +30,6 @@ module Arel
|
|||
Arel::Nodes::Grouping,
|
||||
Arel::Nodes::Offset,
|
||||
Arel::Nodes::Ordering,
|
||||
Arel::Nodes::Having,
|
||||
Arel::Nodes::StringJoin,
|
||||
Arel::Nodes::UnqualifiedColumn,
|
||||
Arel::Nodes::Top,
|
||||
|
@ -206,7 +205,7 @@ module Arel
|
|||
core.wheres << :c
|
||||
core.groups << :d
|
||||
core.windows << :e
|
||||
core.having = :f
|
||||
core.havings << :f
|
||||
|
||||
@visitor.accept core
|
||||
assert_equal [
|
||||
|
@ -216,7 +215,7 @@ module Arel
|
|||
:c, core.wheres,
|
||||
:d, core.groups,
|
||||
:e, core.windows,
|
||||
:f,
|
||||
:f, core.havings,
|
||||
core], @collector.calls
|
||||
end
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ module Arel
|
|||
Arel::Nodes::Grouping,
|
||||
Arel::Nodes::Offset,
|
||||
Arel::Nodes::Ordering,
|
||||
Arel::Nodes::Having,
|
||||
Arel::Nodes::UnqualifiedColumn,
|
||||
Arel::Nodes::Top,
|
||||
Arel::Nodes::Limit,
|
||||
|
|
Loading…
Reference in a new issue