Skip to content

Commit 738da30

Browse files
committed
Fix issues
1 parent 45c4994 commit 738da30

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

README.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Hit `composer update` in the terminal, and you are ready to go next!
2424
### Schema
2525

2626
Storing hierarchies in a database requires additional columns for the table, so these
27-
fields need to be included in the migration. There is a helper for this:
27+
fields need to be included in the migration. Also, the root node is required.
28+
So, basic migration looks like this:
2829

2930
```php
3031
<?php

src/Kalnoy/Nestedset/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function toDictionary($key = null)
3535
/**
3636
* Build tree from node list.
3737
*
38-
* To succesfully build tree "id" and "parent_id" keys must present.
38+
* To succesfully build tree "id", "_lft" and "parent_id" keys must present.
3939
*
4040
* If {@link rootNodeId} is provided, the tree will contain only descendants
4141
* of the node with such primary key value.
@@ -49,7 +49,7 @@ public function toTree($rootNodeId = null)
4949
$dictionary = $this->toDictionary();
5050
$result = new static();
5151

52-
// If root node is not specified we take parent id from node with
52+
// If root node is not specified we take parent id of node with
5353
// least lft value as root node id.
5454
if ($rootNodeId === null)
5555
{

src/Kalnoy/Nestedset/QueryBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public function withDepth($key = 'depth')
8686
"((select count(*) from $table _ where $table.$lft between _.$lft and _.$rgt)-1) as $key"
8787
);
8888

89+
if ($this->columns === null) $this->columns = array('*');
90+
8991
return $this->addSelect($column);
9092
}
9193

tests/NodeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ public function testWithDepthWithCustomKeyWorks()
229229
$this->assertTrue(isset($node['level']));
230230
}
231231

232+
public function testWithDepthWorksAlongWithDefaultKeys()
233+
{
234+
$node = Category::withDepth()->first();
235+
236+
$this->assertTrue(isset($node->name));
237+
}
238+
232239
public function testParentIdAttributeAccessorAppendsNode()
233240
{
234241
$node = new Category(array('name' => 'lg', 'parent_id' => 5));

0 commit comments

Comments
 (0)