如何选择包含关联的字段作为主要实体的字段?

I have Cakephp 3 in a project and I'm doing api rest to get a JSON to get data in mobile devices. I have two tables in associated with a foreign key like this:

  MySql tables 
  ----------------------
  Table Tickets:
  |id|code|price_id|

  Table Prices
  |id|price|

  ----------------------

In TicketsTable CakePHP:

$this->belongsTo('Prices', [
        'foreignKey' => 'price_id',
        'joinType' => 'INNER'
    ]);

In controller when I make REST api:

$this->loadModel('Tickets');
        $entradas = $this-> Tickets->find('all')
            ->contain('Prices')
            ->select(['Tickets.code','Prices.price'])
            ->limit('200')
            ->toArray();

Then this array, parsed to JSON return this:

"result":{  
      "tickets":[  
         {  
            "code":"08998112773",
            "prices":{  
               "prices.price":1
            }
         },
         {  
            "code":"07615265880",
            "prices.prices":{  .........

And I want to return this JSON:

   "result":{  
          "tickets":[  
             {  
                "code":"08998112773",
                "price":1
             },
             {  
                "code":"07615265880",
                "price":1  .........

That is, that prices do not insert into a new array and that the name of the table does not appear in the field name.

Thanks a lot!!!!

You could use use Cake\Collection\Collection::map() to create a new array:

$tickets = [
    'result' => [
        'tickets' => [
            [
                'code' => '123',
                'prices' => [
                    'prices.price' => '2'
                ]
            ],
            [
                'code' => '312423',
                'prices' => [
                    'prices.price' => '4'
                ]
            ]
        ]
    ]
];

$collection = new Collection($tickets['result']['tickets']);

$new = $collection->map(function ($value, $key) {
    return [
        'code' => $value['code'], 
        'price' => $value['prices']['prices.price']
    ];
});

$result = $new->toArray();

debug(json_encode(['result' => ['tickets' => $new]], JSON_PRETTY_PRINT)); 
die;

The output is:

{
    "result": {
        "tickets": [
            {
                "code": "123",
                "price": "2"
            },
            {
                "code": "312423",
                "price": "4"
            }
        ]
    }
}