You need to send Bredbook.id
in your data array:
<?php
echo $this->Form->create('Bredbook');
//It can be any other attribute, but need some Breedbook data
echo $this->Form->input('Bredbook.id', array('value' => $id));
echo $this->Form->input(
'Genre',
array(
'options' =>$genres,
'empty' => false
)
);
echo $this->Form->end('Validate');
Or make sure your $this->request->data
looks similar to this before saving:
Array
(
[Bredbook] => Array
(
//It can be any other attribute, but need some Breedbook data
[id] => 1
)
[Genre] => Array
(
[Genre] => Array
(
[0] => 1
)
)
)
This Solution will work also work when you are creating a new Bredbook
as long as you send some data of that Model, it doesn't need to be the id
, you can also send name or other attributes from your Bredbook
Model. If you send Bredbook.id
it will not create a new record and only make the associations, but if you don't send the id
and send other attributes (like name
for example) it will create a new record and will associate it with the Genre
data your are sending.