/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ProductModel::find()->select(['p.*', 'pc.*'])->from(ProductModel::tableName() . ' p')->joinWith(['prices' => function ($q) { $q->from(Price::tableName() . ' pc'); }]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['p.id' => $this->id, 'p.group_id' => $this->group_id, 'p.category_id' => $this->category_id, 'p.status' => $this->status, 'pc.price_category_id' => $this->price_category_id]); $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }