Open euglv opened 9 years ago
@euglv
Example
public function search($params)
{
$query = Order::find()->andWhere([static::tableName() . '.locked' => 0])->joinWith('user')->orderBy('id desc');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
static::tableName() . '.id' => $this->id,
static::tableName() . '.status' => $this->status,
static::tableName() . '.type' => $this->type,
static::tableName() . '.payment_type' => $this->payment_type,
static::tableName() . '.restaurant_id' => $this->restaurant_id,
static::tableName() . '.delivery_time' => $this->delivery_time,
static::tableName() . '.discount_percent' => $this->discount_percent,
static::tableName() . '.new' => $this->new,
static::tableName() . '.first' => $this->first,
static::tableName() . '.locked' => $this->locked,
static::tableName() . '.persons' => $this->persons,
static::tableName() . '.price' => $this->price,
static::tableName() . '.sale_price' => $this->sale_price,
static::tableName() . '.user_id' => $this->user_id,
static::tableName() . '.created_at' => $this->created_at,
static::tableName() . '.updated_at' => $this->updated_at,
]);
if ($this->phone) {
$this->phone = AppHelper::clearPhone($this->phone);
}
$query
->andFilterWhere(['like', static::tableName() . '.clear_phone', $this->phone])
->orFilterWhere(['like', User::tableName() . '.phone_clean', $this->phone])
->andFilterWhere(['like', static::tableName() . '.name', $this->name])
->orFilterWhere(['like', User::tableName() . '.username', $this->name])
->andFilterWhere(['like', static::tableName() . '.comment', $this->comment])
->andFilterWhere(['like', static::tableName() . '.sale_text', $this->sale_text]);
return $dataProvider;
}
In your case
public function search($params)
{
$query = Object::find()->joinWith('translations');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
//And so on
}
I'm use like this script but problem with summary of gridview. I have 10 record but in summary of gridview show 20 items
@kongoon call distinct()
in your query. Object::find()->joinWith('translations')->distinct()
This code:
throws SQL error when params include multilingual fields.