Last Updated: February 25, 2016
·
1.018K
· zeroeth

CakePHP 3.0 HasAndBelongsToMany Input Broken on Edit

Upgrading CakePHP 3.0->3.1 will save mondo head scratching about check-boxs/multi-selects not working right for HasAndBelongsToMany.

3.0 will save the relations in the join table, but will not show them as selected on further edits.

All you should need in your view for it to work is:
(Example is Cart HasAndBelongsToMany Items), editing Cart.

$this->Form->input('Item', array('multiple' => 'checkbox'));

or

$this->Form->input('Item', array('multiple' => true));

And in your controller action

$this->set('items', $this->Cart->Item->find('list'));