Skip to content

Commit

Permalink
Alias order field in findTreeList().
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Dec 3, 2016
1 parent ae2099f commit 073a127
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ORM/Behavior/TreeBehavior.php
Expand Up @@ -483,10 +483,12 @@ function ($field) {
*/
public function findTreeList(Query $query, array $options)
{
$left = $this->_table->aliasField($this->config('left'));

$results = $this->_scope($query)
->find('threaded', [
'parentField' => $this->config('parent'),
'order' => [$this->config('left') => 'ASC'],
'order' => [$left => 'ASC'],
]);

return $this->formatTreeList($results, $options);
Expand Down
10 changes: 9 additions & 1 deletion tests/TestCase/ORM/Behavior/TreeBehaviorTest.php
Expand Up @@ -256,7 +256,15 @@ public function testFindTreeList()
{
$table = TableRegistry::get('MenuLinkTrees');
$table->addBehavior('Tree', ['scope' => ['menu' => 'main-menu']]);
$result = $table->find('treeList')->toArray();
$query = $table->find('treeList');

$result = null;
$query->clause('order')->iterateParts(function ($dir, $field) use (&$result) {
$result = $field;
});
$this->assertEquals('MenuLinkTrees.lft', $result);

$result = $query->toArray();
$expected = [
1 => 'Link 1',
2 => '_Link 2',
Expand Down

0 comments on commit 073a127

Please sign in to comment.