lib/fertile_forest/modules/finders.rb
#
# Find offsetted sibling node from base node.
#
# @param  base_obj [Entity|Integer] Base node|id to find.
# @param  offset [Integer]  Order in child nodes.
# @param  columns [Array] Columns for SELECT clause.
# @return [Entity] Offsetted sibling node from base node.
# @return [nil] No offsetted sibling node.
#
Find offsetted sibling node from base node.
Find offsetted sibling node from base node .
def offset_sibling(base_obj, offset, columns = nil)
            base_node = ff_resolve_nodes(base_obj)
            return nil if base_node.blank?
            parent_node = genitor(base_node)
            return nil if parent_node.blank?
            sibling_nodes = children(parent_node, [@_id]).all
            return nil if sibling_nodes.blank?
            base_id = base_node.id
            nth = nil
            Array(sibling_nodes).each.with_index do |node, i|
              if node.id == base_id
                nth = i
                break
              end
            end
            return nil if nth.nil?
            offset = offset.to_i
            return nil if nth + offset < 0
            nth_child(parent_node, nth + offset, columns)
          end
def offset_sibling ( base_obj , offset , columns = nil ) base_node = ff_resolve_nodes ( base_obj ) return nil if base_node . blank? parent_node = genitor ( base_node ) return nil if parent_node . blank? sibling_nodes = children ( parent_node , [ @_id ] ) . all return nil if sibling_nodes . blank? base_id = base_node . id nth = nil Array ( sibling_nodes ) . each . with_index do | node , i | if node . id == base_id nth = i break end end return nil if nth . nil? offset = offset . to_i return nil if nth + offset < 0 nth_child ( parent_node , nth + offset , columns ) end
Find offsetted sibling node from base node.
Find offsetted sibling node from base node .
# OFFSET -1 make an error # Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; # check the manual that corresponds to your MySQL server version for the right syntax to use near '-1' at line 1
Offsetted sibling node from base node.
Offsetted sibling node from base node .
Entity
No offsetted sibling node.
No offsetted sibling node .
nil
base_obj
Base node|id to find.
Base node|id to find .
offset
Order in child nodes.
Order in child nodes .
columns
Columns for SELECT clause.
Columns for SELECT clause .