Class: ActiveRecord::Refined::AST::Quantified

Inherits:
Node
  • Object
show all
Includes:
SetSubquery
Defined in:
lib/active_record/refined/ast.rb

Overview

ANY and ALL, which stand on the right of a comparison and say how many of the subquery's rows have to satisfy it. Where a scalar subquery has to return one row, these take as many as come.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(kind, relation) ⇒ Quantified

Returns a new instance of Quantified.



1238
1239
1240
1241
1242
1243
1244
1245
# File 'lib/active_record/refined/ast.rb', line 1238

def initialize(kind, relation)
  unless relation.is_a?(ActiveRecord::Relation)
    raise ArgumentError,
      "#{kind} takes a relation as its subquery; a list is what in? takes"
  end
  @kind = kind
  @relation = relation
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



1236
1237
1238
# File 'lib/active_record/refined/ast.rb', line 1236

def kind
  @kind
end

#relationObject (readonly)

Returns the value of attribute relation.



1236
1237
1238
# File 'lib/active_record/refined/ast.rb', line 1236

def relation
  @relation
end

Instance Method Details

#to_arel(_table, _model) ⇒ Object

The subquery goes in as its own AST rather than as the manager, which would parenthesise it a second time -- and to PostgreSQL ANY ((SELECT ...)) is ANY of one scalar, which it refuses.



1250
1251
1252
# File 'lib/active_record/refined/ast.rb', line 1250

def to_arel(_table, _model)
  Arel::Nodes::NamedFunction.new(kind, [set_subquery(relation, kind).ast])
end