0

I have 2 models: Attorney and Powers.

Where: Attorney HABTM Powers

When I add a new Attorney, I select many checkboxes that correspond to the Powers.

My question is: When I edit an Attorney, how do make the checkboxes appear selected?

Sorry my bad english.

Nunser
  • 4,512
  • 8
  • 25
  • 37
Igor Martins
  • 2,015
  • 7
  • 36
  • 57

1 Answers1

0

You need to actually retrieve the HABTM data.

So, for instance, you can use CakePHP's Containable Behavior and get them like this:

$attorney = $this->Attorney->find('first', array(
    'conditions' => array(
        'id' => $id
    ),
    'contain' => array(
        'Power'
    )
));

Then, assuming you name your form-field correctly, they'll populate checked or unchecked automatically.

Without that, you would just be receiving the Attorney data, and the View would have no idea which to check or not.

Dave
  • 28,833
  • 23
  • 113
  • 183