lazychaser / laravel-nestedset

Effective tree structures in Laravel 4-8
3.66k stars 472 forks source link

Problem with fixTree and not null parent_id #543

Open tarikhagustia opened 2 years ago

tarikhagustia commented 2 years ago

Hello, i have a problem when adding nestedset to running project. my project using parentid as a parent_id key so i add this line into my model

public function getParentIdName()
{
        return 'parentid';
}

but when running MyModel::fixTree(); some parent_id record goes NULL, i have double check that parentid was exist on database.

PS . my old application using parentid 0 zero when not having a parent (root directory)

thanks

jkurowski commented 1 year ago

In NodeTraite file find:

protected function setParent($value)
{
    $this->setParentId($value ? $value->getKey() : null)
        ->setRelation('parent', $value);

    return $this;
}

Change to 0 :)