CakePHP: Do not retrieve the id field in find ()

I would like to get some columns from a table without an id column, but CakePHP continues to add it to the find() array. What to do to solve this problem?

+4
source share
1 answer

Use the search options to set the desired fields:

 $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 receiving the associated model data, the cake uses an identifier to receive the associated data in the external table. If you think about it, how else will CakePHP do this?

If you really need to remove the id column, you can do this after calling find:

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

Source: https://habr.com/ru/post/1336371/


All Articles