title: How combine data from two models and sort them by created date (time object) in cakephp?
body: <p>The models Messages and Files belongs to Conversations.
  Both Messages and Files have a created DATETIME field.</p>
  
  <p>I want to select all messages and files that belongs to a specific conversation and them into the same feed based on created date.</p>
  
  <p>How?</p>
  
  <p>This is what I have tried.</p>
  
  <pre><code>//Get us a conversation with all Files and Messages
  $conversations = $this-&gt;Users-&gt;Conversations-&gt;find();
  $conversations-&gt;contain([
    'Files' =&gt; function ($q)
               {
                 return $q-&gt;order('Files.created ASC');
               },
    'Messages' =&gt; function ($q)
                  {
                    return $q-&gt;order('Messages.created ASC');
                  },
    'Messages.Users',
    ]);
    $conversations-&gt;where(['Conversations.id' =&gt; $conversationID]);
  
  //Now we want to sort the files an messages according to created date
  $converted = $conversations-&gt;toArray();
  $allEntities = array_merge($converted[0]['files'],$converted[0]['messages']);
  $allEntities = Hash::sort($allEntities,'{n}.created','asc');
  </code></pre>
  
  <p>That works like a charm on any field that is not a time object, for instance id.</p>
  
  <p>I have read this question <a href="https://stackoverflow.com/questions/13158565/combining-lists-of-data-from-multiple-models-and-sort-them-by-date-created-in-ca">Combining lists of data from Multiple Models and sort them by date created in cakephp</a> </p>
  
  <p>but since cakephp 3 converts datetime into time objects i can't get Hash::sort to work.</p>
  
  <p>One way could be if it's possible to turn the time object off somehow. It mostly makes things more troublesome for me.</p>
  
  <p>Any suggestions?</p>