I am having a bear of a time saving the simplest record from a model called ItemView:
if($this->save($this->data)) {
echo 'worked';
} else {
echo 'failed';
}
Where $this->data is:
Array
(
[ItemView] => Array
(
[list_id] => 1
[user_id] => 1
)
)
And my table is:
CREATE TABLE IF NOT EXISTS `item_views` (
`id` int(11) NOT NULL auto_increment,
`list_id` int(11) NOT NULL,
`user_id` int(11) default NULL,
`user_ip` int(10) unsigned default NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED AUTO_INCREMENT=1 ;
Looking at the query dump in debug mode, Cake isn't even attempting an INSERT, so I have no idea how to debug.
Any help would be appreciated.
Wow, two miserable hours of my life wasted.
Remember that your beforeSave()
must return true
!
To debug Model->save() check the validation errors and the last sql query
$this->Model->save($data);
debug($this->Model->validationErrors); //show validationErrors
debug($this->Model->getDataSource()->getLog(false, false)); //show last sql query
In cakephp 3.x, you can debug during insert/update
if ($this->TableName->save($entity)) {
// success
} else {
// if not save, will show errors
debug($entity->errors());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With