Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

error in refresh tree after delete node #259

Open
mogahead opened this issue Jan 23, 2018 · 4 comments
Open

error in refresh tree after delete node #259

mogahead opened this issue Jan 23, 2018 · 4 comments

Comments

@mogahead
Copy link

mogahead commented Jan 23, 2018

|--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

@lazychaser
Copy link
Owner

Are you aplying defaultOrder when selecting nodes?

@mogahead
Copy link
Author

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

@mogahead
Copy link
Author

mogahead commented Jan 25, 2018

@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
Copy link

fauziasakinah525 commented Oct 20, 2024

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();
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants