save - CakePHP: beforeSave not working with saveMany? -


so, reason, data in beforesave callback, though works on single records, not work when using savemany.

what gives? if following:

public function beforesave() {     $this->data['foo'] = 'bar'     die($this->data); } 

i can see in fact $this->data does changed, savemany ignores , saves original data instead.

make sure include model name when manipulating $this->data, e.g. $this->data['event']['foo'] = bar. sure method returns true or save fail.


edit

i whipped quick example , seems working me, see code below. suspicion maybe calling savemany incorrectly , passing whole $this->request->data object it's hard guess without seeing call well.

view

<?php echo $this->form->create('parenttable'); ?>     record 1: <br />     <?php echo $this->form->input('parenttable.0.name'); ?>      record 2: <br />     <?php echo $this->form->input('parenttable.1.name'); ?> <?php echo $this->form->end('submit'); ?> 

controller

public function index() {     if ($this->request->data) {         $this->parenttable->savemany($this->request->data['parenttable']);     } } 

model

public function beforesave() {     $this->data['parenttable']['name'] .= ' modified';     return true; } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -