/** * returns actions that was made by this user on some videos * @return ActiveQuery */ public function getVideoActions() { return $this->hasMany(VideoAction::className(), ['user_id' => 'id'])->where(['status' => 'active']); }
/** * Finds the Video Action model based on its primary key value. * If the model is not found, will create new model. * @param integer $video_id * @param integer $user_id * @return Video Action the loaded model * @throws NotFoundHttpException */ protected function findVideoAction($video_id, $user_id) { if (Video::findOne($video_id) !== null) { if (($model = VideoAction::find()->where(['video_id' => $video_id, 'user_id' => $user_id])->one()) !== null) { return $model; } else { return new VideoAction(); } } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getVideoAction() { return $this->hasOne(VideoAction::className(), ['video_id' => 'id'])->where(['user_id' => Yii::$app->user->id])->all(); }