/** * Creates a new Subject model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Subject(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $subjechHasUserModel = new SubjectHasUser(); $subjechHasUserModel->user_id = Yii::$app->user->getId(); $subjechHasUserModel->id = $model->id; $userModel = User::findOne(Yii::$app->user->getId()); $subjechHasUserModel->user_department_id = $userModel->department_id; $subjechHasUserModel->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * @return \yii\db\ActiveQuery */ public function getSubjectHasUsers() { return $this->hasMany(SubjectHasUser::className(), ['user_id' => 'id', 'user_department_id' => 'department_id']); }
/** * @return \yii\db\ActiveQuery */ public function getSubjectHasUsers() { return $this->hasMany(SubjectHasUser::className(), ['id' => 'id']); }