Method: ROM::Relation::Combined#node

Defined in:
lib/rom/relation/combined.rb

#node(name) {|relation| ... } ⇒ Relation

Return a new combined relation with adjusted node returned from a block

Examples:

with a node identifier

combine(:tasks).node(:tasks) { |tasks| tasks.prioritized }

with a nested path

combine(tasks: :tags).node(tasks: :tags) { |tags| tags.where(name: 'red') }

Parameters:

  • name (Symbol)

    The node relation name

Yield Parameters:

  • relation (Relation)

    The relation node

Yield Returns:

Returns:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rom/relation/combined.rb', line 86

def node(name, &block)
  if name.is_a?(Symbol) && !nodes.map { |n| n.name.key }.include?(name)
    raise ArgumentError, "#{name.inspect} is not a valid aggregate node name"
  end

  new_nodes = nodes.map { |node|
    case name
    when Symbol
      name == node.name.key ? yield(node) : node
    when Hash
      other, *rest = name.flatten(1)
      if other == node.name.key
        nodes.detect { |n| n.name.key == other }.node(*rest, &block)
      else
        node
      end
    else
      node
    end
  }

  with_nodes(new_nodes)
end