public function getMonitoring2s() { return $this->hasMany(Monitoring2::className(), ['year_id' => 'id']); }
public function searchAll($params) { if (Yii::$app->user->can('admin')) { $query = Monitoring2::find()->joinWith('user.profile.region'); } else { $query = Monitoring2::find()->joinWith('user.profile.region')->where([Monitoring2::tableName() . '.user_id' => Yii::$app->user->id]); } $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $query->all(); } $query->andFilterWhere(['user_id' => $this->user_id, 'month_id' => $this->month_id, 'year_id' => $this->year_id, 'date' => $this->date, Region::tableName() . '.id' => $this->region, Monitoring2::tableName() . '.status' => $this->status]); return $query->all(); }
/** * Finds the Monitoring2 model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Monitoring2 the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Monitoring2::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }