title: Yii2 json response converts arrays to JSON objects, not json arrays
body: <p>I have a yii2 model and relations.<br>
  Yii2 response format set to JSON.<br>
  I want to return model with its relationships (one-to-many) and so far everything was fine.  </p>
  
  <p>However, in this case for one of model relationships JSON response encodes into JSON object {}, not array []. And I can't figure out why exactly? For other relationships it is an array.   </p>
  
  <p>Below is var_dump of a model. The problematic relations is <code>items</code></p>
  
  <pre><code>/backend/controllers/TasksController.php:181:
  object(app\models\Task)[163]
    private '_attributes' (yii\db\BaseActiveRecord) =&gt; 
      array (size=6)
        'id' =&gt; int 9
        'title' =&gt; string 'Sample dnewsd' (length=13)
        'mode' =&gt; string 'onlyads' (length=7)
        'deployed' =&gt; int 0
        'start_time' =&gt; string '2017-11-16 00:00:00' (length=19)
        'end_time' =&gt; null
    private '_oldAttributes' (yii\db\BaseActiveRecord) =&gt; 
      array (size=6)
        'id' =&gt; int 9
        'title' =&gt; string 'Sample dnewsd' (length=13)
        'mode' =&gt; string 'onlyads' (length=7)
        'deployed' =&gt; int 0
        'start_time' =&gt; string '2017-11-16 00:00:00' (length=19)
        'end_time' =&gt; null
    private '_related' (yii\db\BaseActiveRecord) =&gt; 
      array (size=3)
        'items' =&gt; 
          array (size=2)
            0 =&gt; 
              object(app\models\TaskItem)[178]
                ...
            2 =&gt; 
              object(app\models\TaskItem)[201]
                ...
        'devices' =&gt; 
          array (size=0)
            empty
        'deviceGroups' =&gt; 
          array (size=0)
            empty
  </code></pre>
  
  <p>Here is the JSON return when I edit model:</p>
  
  <pre><code>{
      "status": "ok",
      "data": {
          "id": 9,
          "title": "Sample task",
          "mode": "onlyads",
          "deployed": 0,
          "start_time": "2017-11-16 00:00:00",
          "end_time": null,
          "items": {
              "0": {
                  "id": 2,
                  "image_url": "/media/lightboxes/pictures/ad_.jpg",
                  "duration": 20,
                  "task_id": 9
              },
              "2": {
                  "id": 46,
                  "image_url": "/media/lightboxes/pictures/ad_46.jpg",
                  "duration": 20,
                  "task_id": 9
              }
          },
          "devices": [],
          "deviceGroups": []
      }
  }
  </code></pre>
  
  <p>You can see that items is not a JSON array: <code>items : {}</code></p>
  
  <p>In another action - GET the same model the returned JSON has <code>items: []</code>:</p>
  
  <pre><code>{
      "status": "ok",
      "data": {
          "id": 9,
          "title": "Sample dnewsd",
          "mode": "onlyads",
          "deployed": 0,
          "start_time": "2017-11-16 00:00:00",
          "end_time": null,
          "items": [
              {
                  "id": 2,
                  "image_url": "/media/lightboxes/pictures/ad_.jpg",
                  "duration": 20,
                  "task_id": 9
              },
              {
                  "id": 46,
                  "image_url": "/media/lightboxes/pictures/ad_46.jpg",
                  "duration": 20,
                  "task_id": 9
              }
          ],
          "devices": [],
          "deviceGroups": []
      }
  }
  </code></pre>
  
  <p>Here is var_dump for the same model in GET action:</p>
  
  <pre><code>/srv/www/erp-ang/backend/controllers/TasksController.php:55:
  object(app\models\Task)[163]
    private '_attributes' (yii\db\BaseActiveRecord) =&gt; 
      array (size=6)
        'id' =&gt; int 9
        'title' =&gt; string 'Sample dnewsd' (length=13)
        'mode' =&gt; string 'onlyads' (length=7)
        'deployed' =&gt; int 0
        'start_time' =&gt; string '2017-11-16 00:00:00' (length=19)
        'end_time' =&gt; null
    private '_oldAttributes' (yii\db\BaseActiveRecord) =&gt; 
      array (size=6)
        'id' =&gt; int 9
        'title' =&gt; string 'Sample dnewsd' (length=13)
        'mode' =&gt; string 'onlyads' (length=7)
        'deployed' =&gt; int 0
        'start_time' =&gt; string '2017-11-16 00:00:00' (length=19)
        'end_time' =&gt; null
    private '_related' (yii\db\BaseActiveRecord) =&gt; 
      array (size=3)
        'items' =&gt; 
          array (size=2)
            0 =&gt; 
              object(app\models\TaskItem)[178]
                ...
            1 =&gt; 
              object(app\models\TaskItem)[184]
                ...
        'devices' =&gt; 
          array (size=0)
            empty
        'deviceGroups' =&gt; 
          array (size=0)
            empty
  </code></pre>
  
  <p>Any clue why could this happen?</p>