开发者

CakePHP: Do not retrieve id field in find()

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜