Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Deleting root node with orphan_strategy as adopt not setting immediate children node as root node #177

Open
amardaxini opened this Issue · 6 comments

4 participants

@amardaxini

While deleting root node and orphan_strategy is adopt immediate child node ancestry value is "" because of that,Node.roots is not fetching correct value.

It can be solved by instance_methods.rb

elsif self.ancestry_base_class.orphan_strategy == :adopt
   descendants.each do |descendant|
      descendant.without_ancestry_callbacks do
          new_ancestry = descendant.ancestor_ids.delete_if { |x| x == self.id }.join("/")
         # check for empty string if it's then set to nil
          new_ancestry = nil if new_ancestry.empty?
         descendant.update_attribute descendant.class.ancestry_column, new_ancestry || nil
       end
    end
@brandonjmckay

I get the same effect.

@brandonjmckay

@amardaxini Did you create a monkeypatch or a forked branch with this fix?

@amardaxini

@brandonjmckay i am not using delete feature for application ,that's why i haven't monkey patch.
But if you want i have added fix in my issue by setting nil if it's empty

@brandonjmckay

I did the same in my Rails controller

@eiapopeia

Did it by overriding my destroy-method on the model:

  def destroy
    children = self.children.to_a
    super
    children.each do |child|
      child.reload
      child.ancestry = nil if child.ancestry.empty?
      child.save
    end
  end

A bugfix in the gem would be better, thought.

@haslinger

The monkeypatch worked for me, so I've create a pull request (#200).
Thank s to @amardaxini, I think this change is harmless, so I dare ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.