CakePHP containable how to do a recursion with join?

151 Views Asked by At

I want to retrieve tree nodes recursively and want to join each [Node] with [Level]
Node:

 ...
public $belongsTo = array(
    'Parent' => array(
        'className' => 'Node',
        'foreignKey' => 'parent_id'
    ),
    'Level' => array(
        'className' => 'Level',
        'foreignKey' => 'level_id'
    )
);
 ...

Controller:

$this->Node->contain(array(
        'Parent.Parent.Parent.Parent.Parent',
    ));
$parentTree = $this->Node->findAllById($id);

the recursion works already but I want each Node to have a Level element and now it's not the case.
How would be the correct contain parameter?
Levels are recursive as well but in this case a want to restrict the recursion - need only the first one

0

There are 0 best solutions below