Class: Pluckr::Schema::Exists

Inherits:
Node
  • Object
show all
Includes:
Conditions
Defined in:
lib/pluckr/schema/exists.rb

Overview

exists :photos -> correlated EXISTS (SELECT 1 FROM photos WHERE ...)

Instance Attribute Summary collapse

Attributes inherited from Node

#output

Instance Method Summary collapse

Methods included from Conditions

#dynamic_where?, #resolved_where

Methods inherited from Node

#scalar?

Constructor Details

#initialize(output:, association:, where: nil, scope: nil) ⇒ Exists

Returns a new instance of Exists.



11
12
13
14
15
16
17
# File 'lib/pluckr/schema/exists.rb', line 11

def initialize(output:, association:, where: nil, scope: nil)
  super(output: output)
  @association = association
  @where = where.respond_to?(:call) ? where : where&.dup&.freeze
  @scope = scope
  freeze
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



9
10
11
# File 'lib/pluckr/schema/exists.rb', line 9

def association
  @association
end

#scopeObject (readonly)

Returns the value of attribute scope.



9
10
11
# File 'lib/pluckr/schema/exists.rb', line 9

def scope
  @scope
end

#whereObject (readonly)

Returns the value of attribute where.



9
10
11
# File 'lib/pluckr/schema/exists.rb', line 9

def where
  @where
end

Instance Method Details

#relation_scoped?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pluckr/schema/exists.rb', line 23

def relation_scoped?
  !scope.nil? || !where.nil?
end

#target_modelObject



19
20
21
# File 'lib/pluckr/schema/exists.rb', line 19

def target_model
  association.klass
end