/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Debt::find()->joinWith('debtPerson'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['debt_person' => SORT_ASC]]]); $dataProvider->sort->attributes['debt_person'] = ['asc' => ['person.person_last_name' => SORT_ASC], 'desc' => ['person.person_last_name' => SORT_DESC]]; $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 $dataProvider; } $query->andFilterWhere(['debt_id' => $this->debt_id, 'debt_sum' => $this->debt_sum, 'debt_person' => $this->debt_person, 'debt_created_at' => $this->debt_created_at]); $query->andFilterWhere(['like', 'debt_comment', $this->debt_comment]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getDebts() { return $this->hasMany(Debt::className(), ['debt_person' => 'person_id']); }