module Ancestry::MaterializedPath2

store ancestry as /grandparent_id/parent_id/ root: a=/,id=1 children=a.id/% == /1/% 3: a=/1/2/,id=3 children=a.id/% == /1/2/3/%

Public Instance Methods

descendant_conditions(object) click to toggle source

deprecated

# File lib/ancestry/materialized_path2.rb, line 29
def descendant_conditions(object)
  t = arel_table
  node = to_node(object)
  t[ancestry_column].matches("#{node.child_ancestry}%", nil, true)
end
indirects_of(object) click to toggle source
# File lib/ancestry/materialized_path2.rb, line 6
def indirects_of(object)
  t = arel_table
  node = to_node(object)
  where(t[ancestry_column].matches("#{node.child_ancestry}%#{ANCESTRY_DELIMITER}%", nil, true))
end
ordered_by_ancestry(order = nil) click to toggle source
# File lib/ancestry/materialized_path2.rb, line 24
def ordered_by_ancestry(order = nil)
  reorder(Arel::Nodes::Ascending.new(arel_table[ancestry_column]), order)
end
siblings_of(object) click to toggle source
# File lib/ancestry/materialized_path2.rb, line 18
def siblings_of(object)
  t = arel_table
  node = to_node(object)
  where(t[ancestry_column].eq(node[ancestry_column]))
end
subtree_of(object) click to toggle source
# File lib/ancestry/materialized_path2.rb, line 12
def subtree_of(object)
  t = arel_table
  node = to_node(object)
  where(descendant_conditions(node).or(t[primary_key].eq(node.id)))
end