title: REST extra fields and join in Yii2
body: <p>I have this schema in my database.</p>
  
  <ul>
  <li>time_sheet</li>
  <li>mission</li>
  <li>position </li>
  <li>order</li>
  </ul>
  
  <p>One mission have many timesheets and one time sheet have just one mission.</p>
  
  <p>One position have many missions and one mission have just one position.</p>
  
  <p>One order have many positions and one position have just one order.</p>
  
  <p>And in my class that extends from <code>yii\rest\IndexAction</code> I have this code (in the <code>prepareDataProvider()</code> method):</p>
  
  <pre><code>$query = $timeSheetModel-&gt;find()
      -&gt;distinct()
      -&gt;joinWith("mission")
      -&gt;joinWith("mission.position")
      -&gt;joinWith("mission.position.order")
      -&gt;where("public.order.id = $id");
  
  $results = new ActiveDataProvider([
      'query' =&gt; $query,    
  ]);
  
  return $results;
  </code></pre>
  
  <p>So how to personalise my extra fields to get a json with the following structure:</p>
  
  <ul>
  <li>timeSheet
  <ul>
  <li>mission</li>
  <li>position</li>
  <li>resource</li>
  <li>order</li>
  </ul></li>
  </ul>