Class: Pluckr::Schema::One

Inherits:
Node
  • Object
show all
Defined in:
lib/pluckr/schema/one.rb

Overview

one :plan, via: :subscription do ... end

Compiles to a LEFT OUTER JOIN plus a hidden presence marker so that "association missing" and "association present with NULL columns" stay distinguishable.

first :comment, via: :comments do ... end and its last counterpart use the same node with pick and order set: one row out of a collection, compiled as correlated subqueries instead of a join.

Instance Attribute Summary collapse

Attributes inherited from Node

#output

Instance Method Summary collapse

Constructor Details

#initialize(output:, association:, scope:, pick: nil, order: nil) ⇒ One

Returns a new instance of One.



17
18
19
20
21
22
23
24
# File 'lib/pluckr/schema/one.rb', line 17

def initialize(output:, association:, scope:, pick: nil, order: nil)
  super(output: output)
  @association = association
  @scope = scope
  @pick = pick
  @order = order&.freeze
  freeze
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



15
16
17
# File 'lib/pluckr/schema/one.rb', line 15

def association
  @association
end

#orderObject (readonly)

Returns the value of attribute order.



15
16
17
# File 'lib/pluckr/schema/one.rb', line 15

def order
  @order
end

#pickObject (readonly)

Returns the value of attribute pick.



15
16
17
# File 'lib/pluckr/schema/one.rb', line 15

def pick
  @pick
end

#scopeObject (readonly)

Returns the value of attribute scope.



15
16
17
# File 'lib/pluckr/schema/one.rb', line 15

def scope
  @scope
end

Instance Method Details

#picked?Boolean

True when this node picks one row out of many rather than following a singular association.

Returns:

  • (Boolean)


28
29
30
# File 'lib/pluckr/schema/one.rb', line 28

def picked?
  !pick.nil?
end

#scalar?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/pluckr/schema/one.rb', line 32

def scalar?
  false
end