Hi,
I know this topic has been beaten to death but I still can’t find a conclusive answer for dealing with many to many relationships.
I have two tables (and models) Portfolio & Service. There is a link table PortfolioService that has PortfolioId and ServiceId as PKs.
I am using the CAdvancedArBehavior behavior to handle the Many to Many saving. All is working well. But…
I am using checkBoxList to render a list of services that a user can check on the portfolio. It works well except when the validation fails for submitting the form. The checkBoxList is cleared and the posted values are not repopulated.
<?php echo $form->labelEx($model, 'services'); ?>
<?php echo $form->checkBoxList($model, 'services',
CHtml::listData(Service::model()->findAll(), 'id', 'name'),
array('attributeitem' => 'id', 'checkAll' => 'Check All')); ?>
<?php echo $form->error($model, 'services'); ?>
I have tried using Relation Widget but I don’t want to use it in my app.
Question: is there a way to use checkBoxList using CAdvancedArBehavior? If not, can you please point me to a "complete" reference for manually managing the Many to Many relationships - I.e. using a 3rd Model to link the 2 parent models.
Thanks!