Yii Framework Forum: How To Populate Checkboxes From Many_Many Relation - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Populate Checkboxes From Many_Many Relation Rate Topic: -----

#1 User is offline   kaygee79 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 01-December 10

Posted 16 October 2012 - 12:43 AM

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?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users