Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why don't you create a method in the node model? </p> <p>Something like:</p> <pre><code> &lt;?php // first argument is a nested array filled with integers (corresponding to node_type_id) //second one id of a node //third one corresponds to the data you want(empty at beginning in most case) public function custom_find($conditions,$id,&amp;$array){ //there may several type of nodes wanted: for instances actors and director of a serie, so we loop foreach($conditions as $key_condition=&gt;$condition){ //test to know if we have reached the 'bottom' of the nested array: if yes it will be an integer '2', if no it will be an array like '2'=&gt;array(...) if(is_array($condition))){ //this is the case where there is deeper levels remaining //a find request: we ask for the node defined by its id, //and the child nodes constrained by their type: ex: all actors of "Breaking Bad" $this-&gt;id=$id; $result=$this-&gt;find('all',array( 'contain' =&gt; array( 'OtherNode' =&gt; array( 'conditions'=&gt;array('node_type_id'=&gt;$key_condition) ) ) ) ); //we add to $array the nodes found. Ex: we add all the actors of the serie, with type_id as key $array[$key_condition]=$result['OtherNode']; //Then on each node we just defined we call the function recursively. Note it's $condition not $conditions foreach($array[$key_condition] as &amp;$value){ $this-&gt;custom_find($condition,$value['Node']['id'],$value); } }else{ //if we simply add data $this-&gt;id=$id; $result=$this-&gt;find('all',array( 'contain' =&gt; array( 'OtherNode' =&gt; array( 'conditions'=&gt;array('node_type_id'=&gt;$value) ) ) ) ); $array[$condition]=$result['OtherNode']; } } } </code></pre> <p>That code is almost certainly wrong, it's just to give you an idea of what I mean.</p> <p>Edit:</p> <p><strong>What it does:</strong></p> <p>it's a recursive function that takes a nested array of conditions and the id of a node and gives back nested array of nodes.</p> <p>For instance: $conditions=array('2','4'=>array('5','6'=>array('4')))</p> <p><strong>How it works:</strong></p> <p>For a single node it gives back all the child nodes corresponding to the condition in the array: then it does the same for the children with the conditions one level deeper, until there is no more levels left. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload