title: CakePhp 'contains' versus a forced joining?
body: <p>So, I'm working with CakePHP on and MVC based project to join together a series of tables. In my research, I found two primary ways of doing these joins.</p>
  
  <p>'contain' - which focuses on using the existing associations in the Model of the MVC framework.</p>
  
  <p>'forced joining' - which is similar to SQL's INNER JOIN type clauses, allowing for multiple joins on specific conditions to occur. </p>
  
  <p>Anyway. I started out by using contain to aggregate the tables together, and it worked, but I discovered when I needed to make a bit of that functionality more complicated, that I had to use forced joins. </p>
  
  <p>So below is my 'contain' way of aggregating the tables and it works, I have a similar structured block of code for a forced joining and I'm wondering why my forced joins aren't working? I did some research in the documentation and everything seems correct. What am I missing?</p>
  
  <p>'contains':</p>
  
  <pre><code>$tags = $this-&gt;OfficialTeams-&gt;Tags-&gt;find('all', ['conditions' =&gt; ['official' =&gt; true], 
       'contain' =&gt; ["Questions.Answers.Posts"] ]);
  </code></pre>
  
  <p>'forced joins'</p>
  
  <pre><code>$options['joins'] = array(
                  array(
                      'table' -&gt; 'Users',
                      'alias' -&gt; 'Users',
                      'type' -&gt; 'INNER',
                      'conditions' -&gt; array('Users.id = Tag.user_id')
                  ),
                  array(
                      'table' -&gt; 'Posts',
                      'alias' -&gt; 'Post',
                      'type' -&gt; 'INNER',
                      'conditions' -&gt; array('Users.id = Posts.user_id')
                  ),
                  array(
                      'table' -&gt; 'Questions',
                      'alias' -&gt; 'Question',
                      'type' -&gt; 'INNER',
                      'conditions' -&gt; array('Questions.post_id = Posts.id')
                  ),
                  array(
                      'table' -&gt; 'Answers',
                      'alias' -&gt; 'Answer',
                      'type' -&gt; 'INNER',
                      'conditions' -&gt; array('Answers.post_id = Posts.id')
                  )
     );
  $options['conditions'] = array(['official' =&gt; true]);
  $tags = $this-&gt;OfficialTeams-&gt;Tags-&gt;find('all', $options);
  </code></pre>
  
  <p>The "OfficialTeams", "Tags", "Answers", "Users", "Posts" are all tables within the SQL database. This code is located in the OfficialTeams controller which is why when doing the finds the "$this" refers to Official Teams first.</p>
  
  <p>I also know why for more complicated joins that 'contain' doesn't work, it's because 'contains' uses the  existing relations from the tables, but it can't utilize a "hasAndBelongsToMany" associations. I found that here at the CakePHP docs.
  <a href="https://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#joining-tables" rel="nofollow noreferrer">https://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#joining-tables</a></p>
  
  <p>In any case, any help regarding <strong>why my forced joins queries aren't working would be much appreciated.</strong> Thanks!</p>
  
  <p>EDIT: Table Relationships.
  <a href="https://i.stack.imgur.com/BsWix.png" rel="nofollow noreferrer">Table Relationships are here</a></p>
  
  <p>EDIT AGAIN: My version is Cake 3.3.10 and as for the expected behavior versus the current behavior. I have data on a form that is rendered and calculated once it's aggregated and pulled from the database from the various tables. The expected behavior is just that two numbers appear (specifically these numbers represent the number of questions/posts/answers by an official team for a specific user). And as for the current behavior, the number of questions/posts/answers is a warning: array_map, argument 2 should be an array. The value of that current piece of data is a null. </p>
  
  <p>Another odd piece of behavior. When I print out the query via a 'throws' call (to force it fail so I can print out the query). The query for both the 'contains' block of code and the 'force joins' block of code is the exact same query. </p>