Class: ActiveRecord::Refined::AST::Exists

Inherits:
Predicate show all
Defined in:
lib/active_record/refined/ast.rb

Overview

EXISTS (SELECT ...) for a relation. Correlate the subquery with the outer table through qualified columns. EXISTS only asks whether a row comes back, so unlike In there is no select list to fix up.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Predicate

#!, #&, #|

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(relation) ⇒ Exists

Returns a new instance of Exists.



1265
1266
1267
# File 'lib/active_record/refined/ast.rb', line 1265

def initialize(relation)
  @relation = relation
end

Instance Attribute Details

#relationObject (readonly)

Returns the value of attribute relation.



1263
1264
1265
# File 'lib/active_record/refined/ast.rb', line 1263

def relation
  @relation
end

Instance Method Details

#to_arel(_table, _model) ⇒ Object



1269
1270
1271
1272
1273
1274
1275
# File 'lib/active_record/refined/ast.rb', line 1269

def to_arel(_table, _model)
  subquery = relation
  if subquery.eager_loading?
    subquery = subquery.send(:apply_join_dependency)
  end
  subquery.arel.exists
end