Hello!
I lost 4 hours trying to do this by searching the forum, but unsuccessfully.
This is my table structure:
+--------------+ +-------------------+ +------------+
| categoria | | categoria_contato | | contato |
+--------------+ +-------------------+ +------------+
|*id_categoria |<<<<<|*id_categoria | |>>|*id_contato |
|nome | |*id_contato |>>| |nome |
+--------------+ +-------------------+ +------------+
In the model of ‘categoria’, there is the following relationship:
'contatos' => array(self::MANY_MANY, 'Contato', 'categoria_contato(id_categoria, id_contato)'),
And in the model of ‘contato’, there is the follow:
'categorias' => array(self::MANY_MANY, 'Categoria', 'categoria_contato(id_contato, id_categoria)'),
On the file ‘_form’ in ‘contato’, got the following:
echo $form->checkBoxList($model, 'categorias', CHtml::listData(Categoria::model()->findAll(array('order' => 'nome')), 'id_categoria','nome'));
I thought it would Yii automatic, as it is put into $ _POST [‘Contato’] a field called ‘categorias’ marked with the ids:
["categorias"]=>
array(6) {
[0]=>
string(1) "6"
[1]=>
string(2) "16"
[2]=>
string(1) "8"
[3]=>
string(2) "13"
[4]=>
string(1) "4"
[5]=>
string(2) "15"
}
What is missing to make the Yii inserts on table ‘categoria_contato’?
Can anyone help me?