etrepat / baum

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.
http://etrepat.com/baum
MIT License
2.24k stars 459 forks source link

Cannot use a string as custom key for eloquent model in v2.x-dev #312

Open chao opened 5 years ago

chao commented 5 years ago

It works just fine in version 1, but after I upgrade Laravel to 5.8 and Baum to v2.x-dev, I got a exception : Could not resolve target node. in Move.php L206.

Are we have to use integer as primary key in version 2?

chao commented 5 years ago

Well, I made some modifications for resolveNode function as following, it works well.

protected function resolveNode($node)
    {
        if (method_exists($node, 'refresh') && is_callable([$node, 'refresh'])) {
            return $node->refresh();
        }

        if ($node instanceof \Illuminate\Database\Eloquent\Model) {
            return $node->newQuery()->find($node->getKey());
        }

        if (!empty($node)) {
           return $this->node->newQuery()->find($node);
        }
        throw new MoveNotPossibleException('Could not resolve target node.');
    }