Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should use "joins" only for things that can't be done with Cake model relationship and Containable. I don't know the details of your database, but I think the find operation can be simplified. Why don't you post the schema for these tables on here?</p> <p>try this:</p> <blockquote> <pre><code>$options = array( 'contain' =&gt; array( 'Answer' =&gt; array( 'conditions' =&gt; array('Answer.type' =&gt; 'answer'), 'Vote' =&gt; array( 'fields' =&gt; array('SUM(Vote.value)'), 'group' =&gt; array('Vote.parent_id') ), 'Comment' =&gt; array( 'conditions' =&gt; array('Comment.type' =&gt; 'comment'), 'Vote' =&gt; array( 'fields' =&gt; array('SUM(Vote.value)'), 'group' =&gt; array('Vote.parent_id') ) ) ), 'Comment' =&gt; array( 'conditions' =&gt; array('Comment.type' =&gt; 'comment'), 'Vote' =&gt; array( 'fields' =&gt; array('SUM(Vote.value)'), 'group' =&gt; array('Vote.parent_id') ) ), 'User', 'Tag' =&gt; array() </code></pre> <p>), 'conditions' => array( 'Question.id' => $id ) );</p> </blockquote> <p>You get the Vote sum value for each answer, comment, and comment for answer. (You might need to add 'hasMany' Vote in the Node model if you haven't done that yet)</p> <p>If instead you want to get one single total sum of Vote for the question, then I'd suggest: get the list of the answers and comments of the question: </p> <blockquote> <p>$lvl1 = find('list','fields'=>array('id'),'conditions'=>array('Node.parent_id'=>$id)) </p> </blockquote> <p>then get list of the comments of the answers </p> <blockquote> <p>$lvl2 = find('list','fields'=>array('id'),'conditions'=>array('Node.parent_id'=>$lvl1)) </p> </blockquote> <p>then just combine the 2 array then do a sum over that.</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.
    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