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 460 forks source link

makeChildOf() - Baum\MoveNotPossibleException #196

Closed huglester closed 9 years ago

huglester commented 9 years ago

Hello,

I would like to note, that I am using this package outside Laravel. Maybe because of this, there can be issues?

I seem not to be able to create childs:

// works
$article1 = Naujienos_m::active()
            ->where('slug', $slug)
            ->first();

// this one works (`comment1` is stored)
        $comment1 = $article1->comments()->create(['body' => 'Super article!']);

// this one works - `comment2` is created
        $comment2 = Comment::create(['body' => "No, it's a really bad article!"]);

// this one gives the error above:
        $comment2->makeChildOf($comment1);

Full error:

Baum\MoveNotPossibleException [ 0 ]: A node cannot be moved to a descendant of itself (inside moved tree).

Do you have any ideas?

Thank you

huglester commented 9 years ago

Hello,

Since I am using this package outside the Laravel, I have registered Eloquent wrong.

I missed this step: $capsule->setEventDispatcher(new Dispatcher(new Container));

Full connection code:

                        $capsule = new Capsule;
            $capsule->addConnection([
                'driver'    => 'mysql',
                'host'      => 'localhost',
                'database'  => 'test',
                'username'  => 'homestead',
                'password'  => 'secret',
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
            ]);
            $capsule->setEventDispatcher(new Dispatcher(new Container));
            $capsule->setAsGlobal();
            $capsule->bootEloquent();