module PgLtree::Callbacks

Public Instance Methods

cascade_destroy() click to toggle source

Destroy child nodes

@return [ActiveRecord::Relation]

# File lib/pg_ltree/callbacks.rb, line 22
def cascade_destroy
  ltree_scope.where("#{self.class.table_name}.#{ltree_path_column} <@ ?", ltree_path_in_database).destroy_all
end
cascade_update() click to toggle source

Update child nodes path

@return [ActiveRecord::Relation]

# File lib/pg_ltree/callbacks.rb, line 12
def cascade_update
  ltree_scope
    .where(["#{self.class.table_name}.#{ltree_path_column} <@ ?", ltree_path_before_last_save])
    .where(["#{self.class.table_name}.#{ltree_path_column} != ?", ltree_path])
    .update_all ["#{ltree_path_column} = ? || subpath(#{ltree_path_column}, nlevel(?))", ltree_path, ltree_path_before_last_save]
end