How to reduce the amount of fields for _joinData in Cake 3.x?

妖精的绣舞 提交于 2019-11-29 15:41:19

You could for example iterate the collection and remove the properties that you're not interested in, something like:

$eventTicketSales->each(function ($row) {
    foreach ($row['approvings'] as $approving) {
        unset($approving['_joinData']);
    }
});

Which could also be done in a result formatter of a query object:

$query->formatResults(function (\Cake\Collection\CollectionInterface $results) {
    return $results->each(function ($row) {
        foreach ($row['approvings'] as $approving) {
            unset($approving['_joinData']);
        }
    });
});

Or, since you seem to want to apply this in JSON representations, you could mark the _joinData property of the Approving entity as hidden, given that you'd generally want to ditch that property when converting entities to arrays or JSON:

class Approving extends Entity {
    // ...

    protected $_hidden = [
        '_joinData'
    ];

    // ...
}

See also

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!