Select all except one field in cakephp 3 query

为君一笑 提交于 2019-12-02 04:33:11

As of CakePHP 3.6 the selectAllExcept() method has been introduced, which will select all columns from the schema that belongs to the given table, except those columns passed in the second argument:

$query->selectAllExcept($table, ['modified', 'created']);

In earlier versions you'd have to do that manually, ie grab all the possible columns from the schema and remove those that you don't want to include, like:

$query->select(
    array_diff($table->schema()->columns(), ['modified', 'created']);
);

On a related note, check the following issue that asks for a deselect functionality: https://github.com/cakephp/cakephp/issues/6904

See also

You could just find all and then at runtime hide what you dont need

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