As juhana mentioned, you do not need to use all the fields returned by your search call. It is not clear what actual problem you are trying to solve, and it would be in your interest to clarify such details in future issues.
For direct requests
For queries directly in your user model, you can use some logic as follows:
public function beforeFind($queryData) { if (empty($queryData['fields'])) { $schema = $this->schema(); unset($schema['password']); unset($schema['email']); foreach (array_keys($schema) as $field) { $queryData['fields'][] = $this->alias . '.' . $field; } return $queryData; } return parent::beforeFind($queryData); }
but
This will not do anything for queries where you request another model, for example.
$results = $PostModel->find('all', array( 'contain' => array('User') ));
In the above case, all user fields will be returned. For such purposes, itβs best to explicitly define your list of fields, rather than relying on any automatic magic:
$results = $PostModel->find('all', array( 'contain' => array('User') 'fields' => array('Post.*', 'User.name') ));
source share