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
Tree only shows upper level #25
Comments
At first sight i can see already something that seems wrong: 39 inserts in |
I did not manually insert them, but when I noticed the first issue I described, I removed the self-referencing entries in This is how I moved an item to its parent:
|
Yes, the self referencing entries have to stay there to allow the correct functioning of the methods. Don't touch anything in the closure table, and use only the methods provided, or it won't work at all. |
Alright, so I've started from scratch, and now when I try to move them to their parent, this happens (the signed position value I mentioned in my original post):
This is how I was moving them:
Edit: And thanks for the link, having a look right now. |
@vjandrea, we should implement ClosureTable\DatabaseSeeder or something, I think. It seems that it could simplify things. |
@ben-joostens please, post here, as separate comments, your actions that leading to exceptions or erroneous behaviour. Also I'd like to see stack traces for all of that situations, also as separate comments. Thanks. |
@franzose Alright, will make work of it tomorrow. |
Alright, here's the step by step. First of all, this is the database structure I start out with: |
I then populate the
Which gives me a database with these contents: |
The next step is where the issue arises. I'll try to move a few items to their parent:
Which throws this error:
It ends up moving 2 items to their parent, which you can see in the export, if I rerun the function, it'll behave the same, add some and then throw an error.
|
Just for completeness, here is an export of the database after I run the function which moves the items to their parent again. It has moved 2 extra items, but the position for the four items is now |
@franzose I hope you have enough information with what I've provided here, if not, let me know. |
I've been playing around with it for a bit, and managed to get a working tree by using the Not sure if this long load time is normal behaviour? |
@ben-joostens, it's strange but I made tests and they doesn't reproduce the behavior you faced. I mean wrong positioning. Test tables are prepared with the following (you can find this code at tests/ClosureTableTestCase.php): // since we use SQLite we have to add foreign keys support manually.
DB::unprepared('PRAGMA foreign_keys = ON;');
Schema::create('pages', function($table){
$table->increments('id')->unsigned();
$table->string('title', 250);
$table->string('excerpt', 500);
$table->text('content');
$table->string('language', 2);
$table->integer('position')->unsigned();
$table->timestamps();
$table->softDeletes();
});
Schema::create('pages_closure', function($table){
$table->increments('ctid');
$table->integer('ancestor')->unsigned();
$table->integer('descendant')->unsigned();
$table->integer('depth')->unsigned();
$table->foreign('ancestor')->references('id')->on('pages')->onDelete('cascade');
$table->foreign('descendant')->references('id')->on('pages')->onDelete('cascade');
$table->index('depth');
}); The code of the test is the following: // ...
list($page, $child1/*, $child2, $child3, $child4 */) = $this->prepareTestedSiblings();
$children = Page::find(range(3, 5));
foreach ($children as $child)
{
$child->moveTo($child1);
}
$this->assertEquals(3, $child1->countChildren());
$this->assertEquals($child1->id, $children[1]->parent()->id);
// ... The test reports Ok. |
@franzose How do I run that test? I'm not familiar with testing tests from installed packages. |
@ben-joostens, open terminal, then |
@ben-joostens, if you get an autoload.php failure when you run |
Ok, here's the output, forgive me if I'm overlooking something simple, I haven't had the time to check out the tests just yet. But wanted to share it anyway. |
@ben-joostens I'm working to fix the errors, anyway there are no failures in the tests, only sql exceptions that i'll correct |
@vjandrea Yep that's what I thought. I'll try and replicate the issue I was encountering with a test. Btw, on those long loading times, can you tell me if that is to be expected? |
@ben-joostens, can you tell me the specs of the machine you're using? That's really not what's expected, normally queries using closure tables are pretty fast. |
@vjandrea specs won't be an issue, it's running on a dual xeon (Intel(R) Xeon(R) CPU E5620 @ 2.40GHz) with 16 cores total and 12 gigs of ram with an SSD for storage. Do you mind showing me an export of a working dataset so I can compare? Or would you rather see a new export now that I was able to build the tree without errors? |
This is what happens when I fetch the 15 descendants of a parent: |
With 33 nested items divided in two root trees i have a loading time of 3.93 seconds for a full rendered page on my local machine (macbook pro), here's the dump http://paste.laravel.com/W3z |
@vjandrea, slow actually... |
This is what happens when I fetch the 15 descendants of a parent @ben-joostens, these weird queries are workaround to set |
First of all I want to add that I'm not sure if my data is correct. There's a few things I noticed when creating my items in the database…
Entries in grades_closure were created, but when moving an item to a parent, only the first one succeeded without error. Every other item added under the same parent throws an error because it tried to add a signed value to the position column.
Let's say there was a sibling under a parent with
position 0
, whenever I moved another sibling under the same parent, it would try to add it with aposition -1
It did however end up adding the new item to the database and the position seems to end up ok.
The second thing I've noticed is that whenever an item was moved to the parent (let's say an item with
id 10
was moved to a parent withid 20
), 2 entries existed in grades_closure:When requesting the tree with these values in the database, loading was very slow (about a second or two) while there are less than 100 items in the database. On top of that, it showed no tree hierarchy.
When removing these items in grades_closure that referenced themselves, load time when requesting the entire tree was OK again, but now it only showed the parents. From the documentation, I get the impression that it should retrieve the entire tree, parents + siblings.
However, requesting the children of a specific parent works without problems, and I can also request the parent of a given child.
Am I doing something wrong or is this intended behaviour?
Also, the documentation left me guessing a bit as to how I go about creating the actual data, I'm sure it's obvious enough when it works, but when something fails, I was left guessing if I went about it the wrong way.
I'd be happy to add to the documentation if I know the correct approach.
For your convenience, here's an sql dump of the two tables: https://dl.dropboxusercontent.com/u/139621/30-09-13_grades.sql
The text was updated successfully, but these errors were encountered: