Saturday, August 20, 2011

Re: Saving multiple records to multiple models

Ok that worked to a degree :)

my array now looks like this:

Array (     [1] => Array         (             [Event] => Array                 (                     [event_type_id] => 2                 )              [EventTransaction] => Array                 (                     [inventory_type_id] => 2867                     [amount] => 123123                 )          )      [2] => Array         (             [Event] => Array                 (                     [event_type_id] => 3                 )              [EventComment] => Array                 (                     [comment] => asdasd                 )          )  )


And I'm throwing the whole thing against a function which does this:

function saveTransactionEvent($data) {
foreach ($data as $row) {
Debugger::dump($row);
$this->saveAll($row);
}
}

The first entry gets successfully saved, the second one doesn't even run..

Both child models are bound to the Event model like this:
$this->Event->bindModel(
array('hasOne' => array('EventTransaction', 'EventComment')), false
);

So they should be bound for the remainder of the request - but the EventComment, and its parent event never get saved....

I've scaffolded an EventComment controller, and that will write a comment fine... any reason why its not working in this context?



On Sun, Aug 21, 2011 at 4:09 AM, WebbedIT <paul@webbedit.co.uk> wrote:
A good related blog post from teknoid:
http://nuts-and-bolts-of-cakephp.com/2009/03/26/saveall-with-multiple-records-and-for-multiple-models/

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: