1
Helo,有人可以解釋我爲什麼會出現此錯誤嗎?我正在做的是我試圖根據id's
篩選我的GridView
,但它顯示此錯誤消息。我試圖搜索相關信息,但找不到有用的信息。SQLSTATE [23000]:完整性約束違規:1052 where子句中的列'id'不明確Yii2
這裏是我的Search
功能:
public function search($params)
{
$query = Sale::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$query->joinWith('item');
$dataProvider->setSort([
'attributes' => [
'id',
'customer_name',
'customer_surname',
'customer_phone',
'customer_email',
'code',
'comment',
'sign',
'price' => [
'asc' =>['item.price' => SORT_ASC],
'desc' =>['item.price' => SORT_DESC],
],
'item_id' => [
'asc' =>['item.name' => SORT_ASC],
'desc' =>['item.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;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);
$query->andFilterWhere(['like', 'customer_name', $this->customer_name])
->andFilterWhere(['like', 'item.name', $this->item_id])
->andFilterWhere(['like','sign', $this->sign])
->andFilterWhere(['like', 'customer_surname', $this->customer_surname])
->andFilterWhere(['like', 'customer_phone', $this->customer_phone])
->andFilterWhere(['like', 'customer_email', $this->customer_email])
->andFilterWhere(['like', 'code', $this->code])
->andFilterWhere(['like', 'comment', $this->comment]);
return $dataProvider;
}
它應該工作,因爲id
已添加到setSort()
和filter
語句...謝謝您的幫助
恩,謝謝你,Yupik .. :)它工作 – devorye