class Dscf::Marketplace::Category
def self.ransackable_associations(_auth_object = nil)
def self.ransackable_associations(_auth_object = nil) %w[parent subcategories products] end
def self.ransackable_attributes(_auth_object = nil)
def self.ransackable_attributes(_auth_object = nil) %w[id name description parent_id created_at updated_at] end
def descendants
def descendants descendants = [] subcategories.each do |subcategory| descendants << subcategory descendants.concat(subcategory.descendants) end descendants end
def parent_not_self_or_descendant
def parent_not_self_or_descendant return unless parent_id if parent_id == id errors.add(:parent_id, "cannot be self-referencing") return end # Check for circular reference in descendants current = self.class.find_by(id: parent_id) while current if current.id == id errors.add(:parent_id, "creates circular reference") break end current = current.parent end end
def root?
def root? parent_id.nil? end