lib/active_record/hierarchical_query/query.rb
# Specify relationship between parent rows and child rows of the
# hierarchy. It can be specified with Hash where keys are parent columns
# names and values are child columns names, or with block (see example below).
#
# @example Specify relationship with Hash (traverse descendants)
#   MyModel.join_recursive do |hierarchy|
#     # join child rows with condition `parent.id = child.parent_id`
#     hierarchy.connect_by(id: :parent_id)
#   end
#
# @example Specify relationship with block (traverse descendants)
#   MyModel.join_recursive do |hierarchy|
#     hierarchy.connect_by { |parent, child| parent[:id].eq(child[:parent_id]) }
#   end
#
# @param [Hash, nil] conditions (optional) relationship between parent rows and
#   child rows map, where keys are parent columns names and values are child columns names.
# @yield [parent, child] Yields both parent and child tables.
# @yieldparam [Arel::Table] parent parent rows table instance.
# @yieldparam [Arel::Table] child child rows table instance.
# @yieldreturn [Arel::Nodes::Node] relationship condition expressed as Arel node.
# @return [ActiveRecord::HierarchicalQuery::Query] self
Specify relationship between parent rows and child rows of the
hierarchy. It can be specified with Hash where keys are parent columns
names and values are child columns names, or with block .
Specify relationship between parent rows and child rows of the hierarchy . It can be specified with Hash where keys are parent columns names and values are child columns names or with block .
def connect_by(conditions = nil, &block)
        if conditions
          block = conditions_to_proc(conditions)
        end
        raise ArgumentError, 'CONNECT BY: Conditions hash or block expected, none given' unless block
        @connect_by_value = block
        self
      end
def connect_by ( conditions = nil , & block ) if conditions block = conditions_to_proc ( conditions ) end raise ArgumentError , 'CONNECT BY: Conditions hash or block expected, none given' unless block @connect_by_value = block self end
Specify relationship between parent rows and child rows of the
hierarchy.
Specify relationship between parent rows and child rows of the hierarchy .
# convert hash to block which returns Arel node
relationship condition expressed as Arel node.
relationship condition expressed as Arel node .
Arel::Nodes::Node
None
ActiveRecord::HierarchicalQuery::Query
conditions
<not_specific>
block
<not_specific>
<not_specific>
child child rows table instance.
child child rows table instance .
]
<not_specific>
Yields both parent and child tables.
Yields both parent and child tables .
example
Specify relationship with Hash (traverse descendants) MyModel.join_recursive do |hierarchy| # join child rows with condition `parent.id = child.parent_id` hierarchy.connect_by(id: :parent_id) end
Specify relationship with Hash ( traverse descendants ) MyModel . join_recursive do |hierarchy| # join child rows with condition ` parent . id = child . parent_id ` hierarchy . connect_by ( id : : parent_id ) end
example
Specify relationship with block (traverse descendants) MyModel.join_recursive do |hierarchy| hierarchy.connect_by { |parent, child| parent[:id].eq(child[:parent_id]) } end
Specify relationship with block ( traverse descendants ) MyModel . join_recursive do |hierarchy| hierarchy . connect_by { |parent child| parent [ : id ] . eq ( child [ : parent_id ] ) } end