Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you have incorrect relations between your models. I guess it will be enough with:</p> <pre><code>// Node Model public $hasAdBelongsToMany = array( 'AssociatedNode' =&gt; array( 'className' =&gt; 'Node', 'foreignKey' =&gt; 'node_id' 'associationForeignKey' =&gt; 'associated_node_id', 'joinTable' =&gt; 'nodes_nodes' ) ); </code></pre> <p>// Tables</p> <p><strong>nodes</strong></p> <ul> <li>id</li> <li>name</li> <li>node_type_id</li> </ul> <p><strong>nodes_nodes</strong></p> <ul> <li>id</li> <li>node_id</li> <li>associated_node_id</li> </ul> <p><strong>node_types</strong></p> <ul> <li>id</li> <li>name</li> </ul> <p>Then you can try using <a href="http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html" rel="nofollow">ContainableBehavior</a> to fetch your data. For Example, to find all TVShows belonging to a TVStation:</p> <pre><code>$options = array( 'contain' =&gt; array( 'AssociatedNode' =&gt; array( 'conditions' =&gt; array( 'AssociatedNode.node_type_id' =&gt; $id_of_tvshows_type ) ) ), conditions =&gt; array( 'node_type_id' =&gt; $id_of_tvstations_type ) ); $nodes = $this-&gt;Node-&gt;find('all', $options); </code></pre> <p><strong>EDIT :</strong></p> <p>You can even have second level conditions (see last example on <a href="http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#containing-deeper-associations" rel="nofollow">this section</a>, look at the 'Tag' model conditions). Try this:</p> <pre><code>$options = array( 'contain' =&gt; array( 'AssociatedNode' =&gt; array( 'conditions' =&gt; array( 'AssociatedNode.node_type_id' =&gt; $id_of_tvshows_type ), 'AssociatedNode' =&gt; array( 'conditions' =&gt; array( 'AssociatedNode.type_id' =&gt; $id_of_actors_type) ) ) ), conditions =&gt; array( 'node_type_id' =&gt; $id_of_tvstations_type ) ); $nodes = $this-&gt;Node-&gt;find('all', $options); </code></pre>
    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.
    1. VO
      singulars
      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