title: CakePHP 3 contain select fields
body: <p>I have the following DB tables: items, users, groups, itemImages.
  There are many to many relations between (items, groups) and (users, groups), and one to many between (items, itemImages).
  All the appropriate foreign keys have been setup in CakePHP as associations.</p>
  
  <p>How can I construct a query with contain() which selects all items and their main image, which are in a group which has been assigned as a main group to a user with a particular id?</p>
  
  <p>To make it clearer, here is what a plain SQL query would look like:</p>
  
  <pre><code>SELECT items.id AS itemId, items.name, itemImages.url AS itemUrl
  FROM items
  INNER JOIN groups_items ON groups_items.item_id = items.id
  INNER JOIN groups ON groups_images.group_id = groups.id
  INNER JOIN groups_users ON groups_users.group_id = groups.id
  INNER JOIN users ON groups_users.user_id = users.id
  INNER JOIN itemImages ON itemImages.item_id = items.id
  WHERE groups_users.isMainGroup = 1
      AND users.id = :userId
      AND itemImages.isMainImage = 1
  </code></pre>
  
  <p>CakePHP code I have for now:</p>
  
  <pre><code>$items = $this-&gt;Items-&gt;find()
              -&gt;hydrate(false)
              -&gt;contain([
                  'Groups.Users' =&gt; function($q) use ($userId){
                      return $q-&gt;where(['isMainGroup' =&gt; 1, 'Users.id' =&gt; $userId]);
                  },
                  'ItemImages' =&gt; function($q){
                      return $q-&gt;where(['isMainImage' =&gt; 1]);
                  },
              ]);
              //-&gt;select(['itemId' =&gt; 'Items.id', 'Items.name', 'itemUrl' =&gt; 'itemImages.url']);
  </code></pre>