Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

makeRoot() fails on already existing items #64

Closed
alxy opened this issue Apr 28, 2014 · 5 comments
Closed

makeRoot() fails on already existing items #64

alxy opened this issue Apr 28, 2014 · 5 comments

Comments

@alxy
Copy link

alxy commented Apr 28, 2014

Hello,

I have a table and want to make it a nested set table. So I added the neccessary columns and adding new elements/items to that table works really well.
However, I have to convert the already existing items to root elements. I tried the following:

Category::find(2)->makeRoot();

However, I'm running into the following error then:

PHP Fatal error:  Uncaught exception 'InvalidArgumentException' with message 'Value must be provided.' in /var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:350
Stack trace:
#0 [internal function]: Illuminate\Database\Query\Builder->where('lft', '<=', NULL)
#1 /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(606): call_user_func_array(Array, Array)
#2 /var/www/vendor/baum/baum/src/Baum/Node.php(405): Illuminate\Database\Eloquent\Builder->where('lft', '<=', NULL)
#3 /var/www/vendor/baum/baum/src/Baum/Node.php(385): Baum\Node->ancestorsAndSelf()
#4 /var/www/vendor/baum/baum/src/Baum/Node.php(756): Baum\Node->getRoot()
#5 /var/www/vendor/d11wtq/boris/lib/Boris/EvalWorker.php(133) : eval()'d code(1): Baum\Node->makeRoot()
#6 /var/www/vendor/d11wtq/boris/lib/Boris/EvalWorker.php(133): eval()
#7 /var/www/vendor/d11wtq/boris/lib/Boris/Boris.php(171): Boris\EvalWorker->start()
#8 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/TinkerCommand.php(49): Boris\Boris in /var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php on line 350

The error is clear, but I don't know how to solve it? Am I doing sth wrong? Or is there any other solution to my problem?

@etrepat
Copy link
Owner

etrepat commented May 2, 2014

From what I can deduce of the error the table has null values for the lft column. That is not possible and the error comes because of that situation.

As you say you already had that table in place and you added the necessary columns, try to run Category::rebuild();. Issuing this method will rebuild the lft, rgt and depth column values provided you have a parent_id field available in your table.

@etrepat
Copy link
Owner

etrepat commented May 13, 2014

Is this still happening?

@alxy
Copy link
Author

alxy commented May 14, 2014

Hey, no you can close it. Probably it was my fault, however I switched over to another solution. I will try it in my next project ( Baum::rebuild() ) and feed back, if it worked ;)

@alxy alxy closed this as completed May 14, 2014
@EhtuCom
Copy link

EhtuCom commented May 26, 2015

Hi, the same happens to me with L5, I created a new project with Baum, but I had some problems so I removed Baum to check it in a more clean enviroment. Now after creating some tasks (is a tasks and subtasks system), I'm trying to enable the "Task extends \Baum\Node". But when for ex I try the $task->makeRoot(); i receive InvalidArgumentException in Builder.php line 457. When I try: \App\Task::rebuild;, with or without force, null return is produced, but when I do $task->save(); I've got the same error: line 457 .. .at Builder->where('lft', '<=', null) ....

In the Task i've: parent_id = 0, lft,rgt,depth and path stays in null.

Any Idea? Thanks in advance!,
David Lyons

@EhtuCom
Copy link

EhtuCom commented May 28, 2015

Solved!!!! The problem was that I've setup parent_id manually and it was not nullable. So I did the migration:
$table->integer('parent_id')->nullable()->default()->change();
Then in the Tinker:
\App\Task::rebuild(true);
And everything is fine!!

Thanks for this package!

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

No branches or pull requests

3 participants