Skip to content

error in refresh tree after delete node  #259

Open
@mogahead

Description

@mogahead

|--node A
|----|node B
|----|---|node C
|----|node D
|----|node E

when delete node C , node D jump to be under node B , this according in error in lft && rgt off node D after refresh

Activity

lazychaser

lazychaser commented on Jan 23, 2018

@lazychaser
Owner

Are you aplying defaultOrder when selecting nodes?

mogahead

mogahead commented on Jan 23, 2018

@mogahead
Author

I didn't select nodes , i just catch the entity then delete it
$deleted = $entity->delete();

mogahead

mogahead commented on Jan 25, 2018

@mogahead
Author

@lazychaser

I have to do very bad practice to fix this issue
$categoryRoot = $this->createModel()->defaultOrder()->ancestorsOf($id)->first();
$entity = $this->find($id);
if($deleted = $entity->delete()){
$categoryRoot->fixTree();
}
This solution make me not satisfied as it's use many queries , spent long execution time , and very risky

fauziasakinah525

fauziasakinah525 commented on Oct 20, 2024

@fauziasakinah525

i fixing with

  1. Order first if dont orders the almost countError after delete()
  2. then reserve the order
  3. then delete
// order first
public function getAllDescendants()
{
    return $this->newQuery()
        ->where('_lft', '>', $this->_lft)
        ->where('_rgt', '<', $this->_rgt)
        ->orderBy('_lft')
        ->get();
}

//get, reserve and delete one by one
$descendants = $drive->getAllDescendants();
foreach ($descendants->reverse() as $descendant) {
    DB::table('drives')->where('id', $descendant->id)->delete();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lazychaser@mogahead@fauziasakinah525

        Issue actions

          error in refresh tree after delete node · Issue #259 · lazychaser/laravel-nestedset