Many to Many relation

if i have this relation between this tables




how i can display status name in employee form and then save selected status id and employee id in EmployeeStatus Table

assume that each employee have many status so we save status id and employee id in EmployeeStatus

thanks alot please i need help in fast time

This question has been asked to death - so if you need answers in fast time: use the forum search.

It was asked as late as today IIRC…

please you can but some good links for this topic please i need fast help


Create Relations in model

    public function relations()


        return array(

            'status'=>array(self::MANY_MANY, 'Status', 'EmployeStatus(EmployeeId, StatusID)'),




Create Form in View

<div class="row">

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

            <?php echo $form->dropDownList($model, 'status',

                    CHtml::listData( Status::model()->findAll(), 'StatusID', 'Name'),

                    array(  'multiple'=>'multiple',


                    )); ?>

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



Create Function in controler

foreach ($_POST['Employee']['status'] as $statusId) {

            $statusJoin = new EmployeStatus;

            $statusJoin->EmployeeId = $model->id;

            $statusJoin->StatusID = $statusId;


Yes We Can