Reputation: 680
I've recently added a new column to my 'users' table (first_name), however when I use
$this->User->find('all')
it will not return first_name in the array.
However, if I use
$this->User->find('all', array('fields' => 'first_id'))
It returns fine.
I have cleared the cache in tmp/cache/model but the problem still persists
Any ideas why I'm having this problem?
Upvotes: 4
Views: 1185
Reputation: 583
It happens whenever you update or edit your database.You simply have to do is change the debug mode if it is set to 0 then put it 2 and vise versa. Your problem will be solved.
Upvotes: 1
Reputation: 338
You'll want to refresh your model cache in the tmp/cache folder.
Optionally, what I have found useful for my development environment is to have a utility function available to run each time I make changes to the model/db layer. In an admin controller I have a clearCache function:
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
public function clearCache(){
Configure::write('debug', 2);
Cache::clear();
$msg = '';
$models = new Folder('../tmp/cache/models');
if(!$models->delete())
$msg .= 'Could not delete models folder!<br>';
else
$msg .= 'Models folder deleted.<br>';
$models = new Folder();
if($models->create('../tmp/cache/models'))
$msg .= 'New models folder created.<br>';
else
$msg .= 'Could not create new models folder!<br>';
$persistent = new Folder('../tmp/cache/persistent');
if(!$persistent->delete())
$msg .= 'Could not delete persistent folder!<br>';
else
$msg .= 'Persistent folder deleted.<br>';
$persistent = new Folder();
if($persistent->create('../tmp/cache/persistent'))
$msg .= 'New models folder created.<br>';
else
$msg .= 'Could not create new persistent folder!<br>';
$views = new Folder('../tmp/cache/views');
if(!$views->delete())
$msg .= 'Could not delete views folder!<br>';
else
$msg .= 'Views folder deleted.<br>';
$views = new Folder();
if($views->create('../tmp/cache/views'))
$msg .= 'New views folder created.<br>';
else
$msg .= 'Could not create new views folder!<br>';
$this->set('results', $msg);
}
Upvotes: 1