Class: Noiseless::AST::Join

Inherits:
Node
  • Object
show all
Defined in:
lib/noiseless/ast/join.rb

Overview

Join node for cross-collection queries (Typesense feature) Allows including related documents from other collections

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#to_h

Constructor Details

#initialize(collection, on:, include_fields: [], strategy: :left) ⇒ Join

Returns a new instance of Join.

Parameters:

  • collection (String, Symbol)

    The collection to join

  • on (Hash)

    Join conditions (e.g., { foreign_key: :local_key })

  • include_fields (Array<String, Symbol>) (defaults to: [])

    Fields to include from joined collection

  • strategy (Symbol) (defaults to: :left)

    Join strategy :left or :inner (default: :left)



14
15
16
17
18
19
20
# File 'lib/noiseless/ast/join.rb', line 14

def initialize(collection, on:, include_fields: [], strategy: :left)
  super()
  @collection = collection.to_s
  @on = on
  @include_fields = Array(include_fields).map(&:to_s)
  @strategy = strategy
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



8
9
10
# File 'lib/noiseless/ast/join.rb', line 8

def collection
  @collection
end

#include_fieldsObject (readonly)

Returns the value of attribute include_fields.



8
9
10
# File 'lib/noiseless/ast/join.rb', line 8

def include_fields
  @include_fields
end

#onObject (readonly)

Returns the value of attribute on.



8
9
10
# File 'lib/noiseless/ast/join.rb', line 8

def on
  @on
end

#strategyObject (readonly)

Returns the value of attribute strategy.



8
9
10
# File 'lib/noiseless/ast/join.rb', line 8

def strategy
  @strategy
end

Instance Method Details

#inner_join?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/noiseless/ast/join.rb', line 26

def inner_join?
  @strategy == :inner
end

#left_join?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/noiseless/ast/join.rb', line 22

def left_join?
  @strategy == :left
end