开发者

CakePHP: Do not retrieve id field in find()

开发者 https://www.devze.com 2023-02-05 14:50 出处:网络
I would like to retrieve some columns from a table, without the id column, but Ca开发者_运维问答kePHP keeps adding it to the find() array.

I would like to retrieve some columns from a table, without the id column, but Ca开发者_运维问答kePHP keeps adding it to the find() array. What should I do to solve this problem?


Use the find params to set the fields you want:

$this->find('all', array(
    'conditions' => array(), //array of conditions
    'fields' => array('field1', 'field2') //array of field names
));

http://book.cakephp.org/2.0/en/models/retrieving-your-data.html

As I noted in the comments, when retrieving related model data, cake uses the id to get the related data in the foreign table. If you think about it, how else would CakePHP do it?

If you really must remove the id column, you can do so after the find call:

$data = $this->Model->find('first', array(
    'conditions' => array(), //array of conditions
));
unset($data['Model']['id']);
0

精彩评论

暂无评论...
验证码 换一张
取 消