So I have Teams HABTM Areas, with the following in the Team model:

  var $hasAndBelongsToMany = array(
    'Area' => array('className' => 'Area',
                    'joinTable' => 'areas_teams',
                    'foreignKey' => 'team_id',
                    'associationForeignKey' => 'area_id',
                    'unique' => false,
                    'order' => 'Area.name ASC',
    )
  );

Adding/deleting teams and area relationships works properly from the
scaffolded actions+views, even when 'multiple' => 'checkbox' is added
to $options for $form->input('Area', ...). However, only with the edit
action, adding 'multiple' => 'checkbox' results in not being able to
save the relationship data in areas_teams. The data is being sent to
the view properly, and the right boxes are checked under 'Area';
changing these and submitting appears to succeed, but nothing is being
changed in the areas_teams table.

Here's the view for teams/edit:

<div class="teams form">
<?php echo $form->create('Team');?>
        <fieldset>
                <legend><?php __('Edit Team');?></legend>
        <?php
          echo $form->input('id');
          echo $form->input('name');
          echo $form->input('Area', array('multiple' => 'checkbox'));
        ?>
        </fieldset>
<?php echo $form->end('Submit');?>
</div>

And the controller action:

  function edit($id = null) {
    if (!$id && empty($this->data)) {
      $this->Session->setFlash(__('Invalid Team', true));
      $this->redirect(array('action'=>'index'));
    }
    if (!empty($this->data)) {
      if ($this->Team->save($this->data)) {
        $this->Session->setFlash(__('The Team has been saved', true));
        $this->redirect(array('action'=>'index'));
      } else {
        $this->Session->setFlash(__('The Team could not be saved.
Please, try again.', true));
      }
    }
    if (empty($this->data)) {
      $this->data = $this->Team->read(null, $id);
    }
    $areas = $this->Team->Area->find('list');
    $this->set(compact('areas'));
  }

Here's an example of data being returned in $this->data upon submit:

Array
(
    [Team] => Array
        (
            [id] => 3
            [name] => AV
        )

    [Area] => Array
        (
            [Area] => Array
                (
                    [0] => 6
                    [1] => 8
                    [2] => 13
                    [3] => 14
                    [4] => 15
                    [5] => 16
                    [6] => 17
                )

        )

)

Any help is appreciated.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to