示例#1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCandidates()
 {
     return $this->hasMany(Candidate::className(), ['election_id' => 'id']);
 }
 /**
  * Adds a candidate.
  * @param integer $userId
  * @param integer $electionId
  * @return mixed
  */
 public function actionAddCandidate($userId, $electionId)
 {
     $candidate = new Candidate();
     $candidate->election_id = $electionId;
     $candidate->user_id = $userId;
     $candidate->save();
     return $this->redirect(['add-candidate-list', 'electionId' => $electionId]);
 }