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!!!!