How to debug when CakePHP Model::save() doesn't attempt an INSERT

ryonlife picture ryonlife · Feb 19, 2009 · Viewed 33.1k times · Source

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.

Answer

ryonlife picture ryonlife · Feb 19, 2009

Wow, two miserable hours of my life wasted.

Remember that your beforeSave() must return true!