Module: Ancestry::MaterializedPath2::InstanceMethods

Defined in:
lib/ancestry/materialized_path2.rb

Instance Method Summary collapse

Instance Method Details

#child_ancestryObject



42
43
44
45
46
# File 'lib/ancestry/materialized_path2.rb', line 42

def child_ancestry
  # New records cannot have children
  raise Ancestry::AncestryException.new(I18n.t("ancestry.no_child_for_new_record")) if new_record?
  "#{attribute_in_database(self.ancestry_base_class.ancestry_column)}#{id}#{self.ancestry_base_class.ancestry_delimiter}"
end

#child_ancestry_before_saveObject



48
49
50
51
52
# File 'lib/ancestry/materialized_path2.rb', line 48

def child_ancestry_before_save
  # New records cannot have children
  raise Ancestry::AncestryException.new(I18n.t("ancestry.no_child_for_new_record")) if new_record?
  "#{attribute_before_last_save(self.ancestry_base_class.ancestry_column)}#{id}#{self.ancestry_base_class.ancestry_delimiter}"
end

#generate_ancestry(ancestor_ids) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/ancestry/materialized_path2.rb', line 54

def generate_ancestry(ancestor_ids)
  if ancestor_ids.present? && ancestor_ids.any?
    "#{self.ancestry_base_class.ancestry_delimiter}#{ancestor_ids.join(self.ancestry_base_class.ancestry_delimiter)}#{self.ancestry_base_class.ancestry_delimiter}"
  else
    self.ancestry_base_class.ancestry_root
  end
end