lib/active_record/hierarchical_query.rb
# Performs a join to recursive subquery
# which should be built within a block.
#
# @example
#   MyModel.join_recursive do |query|
#     query.start_with(parent_id: nil)
#          .connect_by(id: :parent_id)
#          .where('depth < ?', 5)
#          .order_siblings(name: :desc)
#   end
#
# @param [Hash] join_options
# @option join_options [String, Symbol] :as aliased name of joined
#   table (`%table_name%__recursive` by default)
# @yield [query]
# @yieldparam [ActiveRecord::HierarchicalQuery::Query] query Hierarchical query
# @raise [ArgumentError] if block is omitted
Performs a join to recursive subquery
which should be built within a block.
Performs a join to recursive subquery which should be built within a block .
def join_recursive(join_options = {}, &block)
      raise ArgumentError, 'block expected' unless block_given?
      query = Query.new(klass)
      if block.arity == 0
        query.instance_eval(&block)
      else
        block.call(query)
      end
      query.join_to(self, join_options)
    end
def join_recursive ( join_options = { } , & block ) raise ArgumentError , 'block expected' unless block_given? query = Query . new ( klass ) if block . arity == 0 query . instance_eval ( & block ) else block . call ( query ) end query . join_to ( self , join_options ) end
Performs a join to recursive subquery
which should be built within a block.
Performs a join to recursive subquery which should be built within a block .
[ArgumentError] if block is omitted
[ ArgumentError ] if block is omitted
join_options
:as aliased name of joined table (`%table_name%__recursive` by default)
: as aliased name of joined table ( ` %table_name%__recursive ` by default )
block
<not_specific>
<not_specific>
query Hierarchical query
query Hierarchical query
]
<not_specific>
None
example
MyModel.join_recursive do |query| query.start_with(parent_id: nil) .connect_by(id: :parent_id) .where('depth < ?', 5) .order_siblings(name: :desc) end
MyModel . join_recursive do |query| query . start_with ( parent_id : nil ) . connect_by ( id : : parent_id ) . where ( ' depth < ? ' 5 ) . order_siblings ( name : : desc ) end