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 courseMy 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 d开发者_如何学Pythonifferent 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
    ...
  )
  ...
  )
)
According to CakePHP conventions you must provide [course_id] => 1028476 and not [courseid] => 1028476. Check you model bindings as well (capitalizations and underscores). There must be "Course has many CourseTee".
Do this way to save:
if ($this->Course->saveAll($this->data, array('validate' => 'first'))) {
  $this->_flash(__('Successfully saved.', true), 'success');
} else {
  $this->_flash(__('Cannot save. Does not validates.', true), 'error');
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论