Newbie question about Yii and relationships

Hello again

I finally managed to do the relationship correctly, but…what can I do to add a "attribute" to the relationship?

I mean, my users have many activities, but i need to say if one activity in particular has been paid by the user





TABLE Users

userId

name


TABLE Activities

activityId

name


JUNCTION TABLE UsersActivities

userId

activityId

paid ->(this may be YES or NOT)




Users Model




public function relations()

	{

	// NOTE: you may need to adjust the relation name and the related

	// class name for the relations automatically generated below.

	return array(

		'activities' => array(self::HAS_MANY, 'Activities', 'userId'),

		);

	}




Users Controller


public function actionCreate()

	{

		$model=new Users;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Users']))

		{

			$model->attributes=$_POST['Users'];

			if($model->save()){

            foreach ($_POST['Users']['activities'] as $activityId) {

                $activityId = new UsersActivities;

                $activityId->userId = $model->postId;

                $activityId->activityId = $activityId;

                if (!$activityId->save()) print_r($activityId->errors);

            }}

				$this->redirect(array('view','id'=>$model->userId));

		}


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

			'model'=>$model,

		));

	}



This is the SELECT for add activities to an user at users/create




<div class="row">

<?php echo $form->labelEx($model,'choose activities for this user'); ?>

<?php echo $form->dropDownList($model, 'activities', CHtml::listData(

Activities::model()->findAll(), 'activitiesId', 'name'), array('multiple'=>'multiple', 'size'=>5)

); ?>

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

</div>



Any ideas how to get a checkbox with YES - NO next to activity option on the select list?

Thanks!!!

Hello again, i did my homework (redefine the question) but i still getting things wrong…

Try to define the "id" column of "socios" table as AUTO_INCREMENT and remove the validation rules of this column from the model class.

Thanks!!

I updated the topic with a new issue.

Deletion of the original question after it’s been answered can make the whole topic a bit confusing. Please start a new topic for each new subject.