Before I continue, I'd like to state that I am using the latest version of CakePHP v1.2 (not v1.3). I have not checked if the versions differ in their implementations for this specific method.
Models: Post hasMany Comment Comment belongsTo Post Post hasAndBelongsToMany Tags In my tests, the controller's "add" method remains the same: <?php function add() { if(!empty($this->data)) { $this->Post->saveAll($this->data); } } ?> Simple example: I attempt to use saveAll() from the /post/add with an associated comment. My view code can be found here: <?php echo $form->create(); echo $form->input('Post.title'); echo $form->input('Post.body'); echo $form->hidden('Post.user_id', array('value' => 1)); echo $form->input('Comment.comment'); echo $form->input('Comment.author'); echo $form->end('Add Article with Tags and Comment'); ?> I receive an error: SQL Error: 1364: Field 'post_id' doesn't have a default value [CORE \cake\libs\model\datasources\dbo_source.php, line 526 The actual SQL that is run seems to be very skewed (look at number 9): 1 DESCRIBE `posts` 5 5 2 2 DESCRIBE `users` 3 3 3 3 DESCRIBE `comments` 5 5 3 4 DESCRIBE `tags` 3 3 2 5 DESCRIBE `posts_tags` 3 3 2 6 START TRANSACTION 0 0 7 INSERT INTO `posts` (`title`, `body`, `user_id`, `created`) VALUES ('Test title', 'Test body', 1, '2010-08-12 14:26:40') 1 0 8 SELECT LAST_INSERT_ID() AS insertID 1 1 0 9 INSERT INTO `comments` (`comment`, `author`, `created`) VALUES ('2est comment', '2est author', '2010-08-12 14:26:40') 1364: Field 'post_id' doesn't have a default value 0 10 ROLLBACK The actual content/value for the fields were "Test comment", "Test author"...respectively. The returned ID from the "LAST_INSERT_ID()" seems to be getting used in the wrong location. .... Alternatively, if I remove the Comments model from the view and work with the HABTM association between the Tags and Posts with the following view testing this: <?php echo $form->create(); echo $form->input('Post.title'); echo $form->input('Post.body'); echo $form->hidden('Post.user_id', array('value' => 1)); echo $form->input('Tag', array('options'=>array(15,20,30), 'multiple'=>'checkbox')); echo $form->end('Add Article with Tags and Comment'); ?> The save occurs as it should without modification to the post controller's add action.. If I'm simply missing something, please let me know. The test project was created with cake bake using defaults, so I don't believe my own human error in the coding would have caused this (the Post controller's add action was reduced in functionality to limit what the error could be caused from). Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en