How To Populate Checkboxes From Many_Many Relation

Hi folks,

I’ve setup a MANY_MANY relationship, all is well except that the checkboxes are not populated automatically when going into the update form. Does this have to be done manually or did I screw-up the relationship along the way?

Talent.php




public function relations()

{

    return array(

        'union' => array(self::MANY_MANY, 'Union', 'nca_talent_union(talent_id,union_id)'),


    );

}



Union.php




public function relations()

{

    return array(

        'talent' => array(self::MANY_MANY, 'Talent', 'nca_talent_union(talent_id,union_id)'),

    );

}



TalentUnion.php




public function relations()

{

    return array(

        'talent' => array(self::BELONGS_TO, 'Talent', 'talent_id'),

        'union' => array(self::BELONGS_TO, 'Union', 'union_id'),

    );

}



TalentController.php




public function actionUpdate($id)

{

    $model=$this->loadModel($id);


    print_r($model->union);

    

    $this->render('update',array(

        'model'=>$model

    ));

}

_form.php




<?php echo $form->labelEx($model,'unions'); ?>

<?php echo $form->checkBoxList($model, 'unions',CHtml::listData(Union::model()->findAll(array('order' => 'name ASC')), 'union_id', 'name')); ?>

<?php echo $form->error($model,'unions'); ?>



So I am getting a model from $model->union but how do I apply it so that it populates the form checkboxes?