title: Using SQL Functions in cakephp returns error
body: <p>I am following <a href="http://book.cakephp.org/3.0/en/orm/query-builder.html" rel="nofollow">Using SQL Functions</a> to build my query. I tend to get the first due instalment. My query was working (on cakephp3.1) before updating the cakephp to version 3.3 (by composer).</p>
  
  <p>In my Controller</p>
  
  <pre><code>$this-&gt;loadModel('Orders');
  $order = $this-&gt;Orders-&gt;find()
          -&gt;where(['order_id' =&gt; $orderId])
          -&gt;contain([
              'PaymentInstalments' =&gt; function($q) {
                  return $q-&gt;find('firstDue');
              },
              'Users' =&gt; function($q) {
                  return $q-&gt;select(['email']);
              }
  ])
  -&gt;first();
  </code></pre>
  
  <p>On my paymentInstalments Table</p>
  
  <pre><code>public function findFirstDue(Query $query, array $options)
  {
      $alias = $this-&gt;alias();
  
      $query
          -&gt;select([
  //          "id" =&gt; $query-&gt;func()-&gt;min("$alias.id"),  ## This use to work before but now is not working
              'id' =&gt; $query-&gt;func()-&gt;min(function($row){
                  return $row-&gt;id;
              }),
              'order_id', 'amount', 'date_due', 'transaction_id'
          ])
          -&gt;contain([
              'Transactions' =&gt; function($q) {
                  return $q
                      -&gt;select([
                          'id', 'transaction_date'
                      ])
                      -&gt;where(function ($exp, $q) {
                          return $exp-&gt;isNull('transaction_date');
                      });
              }
          ]);
  
      debug($query-&gt;__debugInfo()['sql']);
      die;    
      return $query;
  }
  </code></pre>
  
  <p>Here is print of my query.</p>
  
  <pre><code>'SELECT PaymentInstalments.id AS `PaymentInstalments__id`, PaymentInstalments.order_id AS `PaymentInstalments__order_id`, PaymentInstalments.instalment_num AS `PaymentInstalments__instalment_num`, PaymentInstalments.amount AS `PaymentInstalments__amount`, PaymentInstalments.date_due AS `PaymentInstalments__date_due`, PaymentInstalments.payment_email_sent AS `PaymentInstalments__payment_email_sent`, PaymentInstalments.transaction_id AS `PaymentInstalments__transaction_id`, {
      "id": 41408,
      "order_id": "10000",
      "instalment_num": 1,
      "amount": 100,
      "date_due": "2016-08-25T12:15:00+01:00",
      "payment_email_sent": false,
      "transaction_id": null
  } AS `PaymentInstalments`.`id`, Transactions.id AS `Transactions__id`, Transactions.transaction_date AS `Transactions__transaction_date` FROM payment_instalments PaymentInstalments LEFT JOIN transactions Transactions ON ((Transactions.transaction_date) IS NULL AND Transactions.id = (PaymentInstalments.transaction_id)) WHERE PaymentInstalments.order_id in (:c0)'
  </code></pre>
  
  <p>The problem is if I use <code>"id" =&gt; $query-&gt;func()-&gt;min("$alias.id"),</code> I get this error:</p>
  
  <blockquote>
    <p>You are required to select the "PaymentInstalments.order_id" field(s)</p>
  </blockquote>
  
  <p>And if I use this</p>
  
  <pre><code>'id' =&gt; $query-&gt;func()-&gt;min(function($row){
      return $row-&gt;id;
  }),`
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You
    have an error in your SQL syntax; check the manual that corresponds to
    your MySQL server version for the right syntax to use near '"id":
    41408, "order_id": "10000", "instalment_num": 1, "amount": ' at
    line 2</p>
  </blockquote>
  
  <p>Any help please</p>