/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = NurseShift::find()->leftJoin('nurse', 'nurse_shift.ns_nurseID=nurse.ID'); // add conditions that should always apply here //$query->innerJoin("nurse", "nurse.ID=nurse_shift.ns_nurseID"); //$query->with("profile"); // eager load to reduce number of queries $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); // add extra sort attributes /*$addSortAttributes = ["full_name"]; foreach ($addSortAttributes as $addSortAttribute) { $dataProvider->sort->attributes[$addSortAttribute] = [ 'asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC], 'label' => $this->getAttributeLabel($addSortAttribute), ]; } */ if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['ID' => $this->ID, 'ns_nurseID' => $this->ns_nurseID, 'ns_shiftID' => $this->ns_shiftID, 'ns_type' => $this->ns_type, 'ns_hours' => $this->ns_hours]); $this->addCondition($query, 'full_name', true); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getNurseShifts() { return $this->hasMany(NurseShift::className(), ['ns_shiftID' => 'ID']); }