def maintain_slug
        postfix = nil
        total_count = 0

        while self.class.where(parent_id: parent_id, slug: "#{slug}#{postfix}").where("id != ?", id.to_i).exists? do
          total_count += 1
          postfix = "-#{total_count}"
        end

        if postfix
          self.slug = "#{slug}#{postfix}"
        end
      end
def maintain_slug
        postfix = nil
        total_count = 0

        while self.class.where(parent_id: parent_id, slug: "#{slug}#{postfix}").where("id != ?", id.to_i).exists? do
          total_count += 1
          postfix = "-#{total_count}"
        end

        if postfix
          self.slug = "#{slug}#{postfix}"
        end
      end
Maintain unique slug within parent_id scope.
 If slug is not unique add numeric postfix.