public function search($params) { $query = StudentAddress::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'student_id' => $this->student_id, 'ord' => $this->ord, 'active' => $this->active]); $query->andFilterWhere(['like', 'line1', $this->line1])->andFilterWhere(['like', 'line2', $this->line2])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'state_abbr', $this->state_abbr])->andFilterWhere(['like', 'zip', $this->zip])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @return \app\Models\StudentAddress */ public function getBestAddress() { return StudentAddress::find()->joinWith('student')->where(['student.id' => $this->id])->orderBy(['student_address.ord' => SORT_ASC])->one(); }