Many to Many relation

if i have this relation between this tables

1-Employee(username,EmployeeID)

2-Status(StatusID,Name)

3-EmployeStatus(EmployeeId,StatusID)

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

First:

Create Relations in model




    public function relations()

    {

        return array(

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

        );

    }



Second:

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',

                            'size'=>5,

                    )); ?>

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

        </div>

Finnaly

Create Function in controler


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

            $statusJoin = new EmployeStatus;

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

            $statusJoin->StatusID = $statusId;

        }

Yes We Can