tags:

views:

1574

answers:

3

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.

+3  A: 

Wow, two miserable hours of my life wasted. For future reference, remember that your beforeSave() must return true!

chipotle_warrior
Great! Thanks for saving me those 2 hours! :)
Seb
I spent 8 hours duplicating this and finding the same thing. Wish I had searched SO earlier!
Jasie
ahhh, thanks for saving my life. this problem costs me 2 hours
Ish Kumar
A: 

I don't know if it's related, but in Cake you normally don't write models for join tables.

Mike B
Normally it's not needed, but sometimes it is especially as the project gets more complicated. It makes sense as soon as the model has more than the two id fields.
Caffeine
+1  A: 

this will be helpful and save time
http://teknoid.wordpress.com/2008/06/09/15-essential-cakephp-tips/

RSK