Tuesday, June 1, 2010

saveAll/Save not saving associations

I'm having a problem trying to save/update some associated data. I've
read about a million google returns, but nothing seems to be the
solution. I'm at my wit's end and hope some kind soul here can help.

I'm using 1.3.0-RC4, my database is in InnoDB.

Course has many course_tees
CourseTee belongs to course

My controller function is pretty simple (I've made it as simple as
possible):

if(!empty($this->data))
$this->Course->saveAll($this->data);

I've tried a lot of different variations of that $this-
>data['Course'], save($this->data), etc without luck.

It saves the Course info, but not the CourseTee stuff. I don't get an
error message.

Since I don't know how many tees any given course will have, I
generate the form inputs dynamically in a loop.

$form->input('CourseTee.'.$i.'.teeName', array('error' => false,
'label' => false, 'value'=>$data['course_tees'][$i]['teeName']))

The course inputs are simpler:

$form->input('Course.hcp'.$j, array('error' => false, 'label' =>
false, 'class' => 'form_small_w', 'value'=>$data['Course']['hcp'.$j]))

And this is how my data is formatted:

Array
(
[Course] => Array
(
[id] => 1028476
...
)

[CourseTee] => Array
(
[0] => Array
(
[key] => 636
[courseid] => 1028476
...
)

[1] => Array
(
[key] => 637
[courseid] => 1028476
...
)

...

)
)

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: