Skip to content

Commit 060b053

Browse files
committed
Rename path() to ancestors()
1 parent 738da30 commit 060b053

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

README.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ _Ancestors_ can be obtained in two ways:
117117

118118
```php
119119
// Target node will not be included into result since it is already available
120-
$path = $node->path()->get();
120+
$path = $node->ancestors()->get();
121121
```
122122

123123
or using the scope:
124124

125125
```php
126126
// Target node will be included into result
127-
$path = Category::pathTo($nodeId)->get();
127+
$path = Category::ancestorsOf($nodeId)->get();
128128
```
129129

130130
_Descendants_ can easily be retrieved in this way:

src/Kalnoy/Nestedset/Node.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,12 @@ public function prevSiblings()
136136
}
137137

138138
/**
139-
* Get query for path to the node not including the node itself.
139+
* Get query for ancestors to the node not including the node itself.
140140
*
141141
* @return \Illuminate\Database\Eloquent\Builder
142142
*/
143-
public function path()
143+
public function ancestors()
144144
{
145-
if (!$this->exists) return array();
146-
147145
$query = $this->newQuery();
148146
$grammar = $query->getQuery()->getGrammar();
149147
$table = $this->getTable();

src/Kalnoy/Nestedset/QueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public function whereIsRoot()
4343
}
4444

4545
/**
46-
* Query path to specific node including that node itself.
46+
* Query ancestors of specific node including that node itself.
4747
*
4848
* @param integer $id
4949
*
5050
* @return \Kalnoy\Nestedset\QueryBuilder
5151
*/
52-
public function pathTo($id)
52+
public function ancestorsOf($id)
5353
{
5454
$grammar = $this->getGrammar();
5555
$table = $grammar->wrapTable($this->from);

tests/NodeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@ public function testWithoutRootWorks()
183183
$this->assertNotEquals('store', $result);
184184
}
185185

186-
public function testPathReturnsAncestorsWithoutNodeItself()
186+
public function testAncestorsReturnsAncestorsWithoutNodeItself()
187187
{
188188
$node = $this->findCategory('apple');
189-
$path = $node->path()->lists('name');
189+
$path = $node->ancestors()->lists('name');
190190

191191
$this->assertEquals(array('store', 'notebooks'), $path);
192192
}
193193

194-
public function testPathToReturnsAncestorsWithNode()
194+
public function testAncestorsOfReturnsAncestorsWithNode()
195195
{
196-
$path = Category::pathTo(3)->lists('name');
196+
$path = Category::ancestorsOf(3)->lists('name');
197197

198198
$this->assertEquals(array('store', 'notebooks', 'apple'), $path);
199199
}

0 commit comments

Comments
 (0)