Hallo, i’m newbie in yii2 framework. Now, i’m trying to create data provider in search model using relations and some leftJoin() method.
But, when I add $this->field_from_leftJoin in filterWhere, always getting error unknown property.
And here my SearchModel :
public function search($params)
{
$query = ScheduleProduction::find();
$query->joinWith('idCircuit')
->joinWith('idSchedule')
->leftJoin('detail_order', 'detail_order.id_detail_order = schedule.id_detail_order')
->leftJoin('order_project', 'order_project.id_order = detail_order.id_order')
->where([
'order_project.id_car' => Yii::$app->session->get('carmaker'),
'order_project.id_shift' => Yii::$app->session->get('shift'),
]);
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
],
]);
$dataProvider->sort->attributes['id_order'] = [
'asc' => ['order_project.id_order' => SORT_ASC],
'desc' => ['order_project.id_order' => SORT_ASC]
];
$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;
}
if (Yii::$app->session->get('cutoff') == 1 || Yii::$app->session->get('cutoff') == 2 || Yii::$app->session->get('cutoff') == 5 || Yii::$app->session->get('cutoff') == 6 ) {
$query->andFilterWhere([
'workdate' => Yii::$app->session->get('workdate')
]);
}
if (Yii::$app->session->get('cutoff') == 3 || Yii::$app->session->get('cutoff') == 7) {
$query->andFilterWhere(['order_project.id_order' => $this->id_order])
->andFilterWhere(['or',
['circuit.process' => 'S-JOINT'],
['circuit.process' => 'TWIST'],
['circuit.process' => 'BONDER'],
['circuit.process' => 'SHIELD']
]);
}
if (Yii::$app->session->get('cutoff') == 4 || Yii::$app->session->get('cutoff') == <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> {
$query->andFilterWhere(['order_project.id_order' => $this->id_order])
->andFilterWhere([
'circuit.process' => 'SUB',
]);
}
// grid filtering conditions
$query->andFilterWhere([
'id_sch_prod' => $this->id_sch_prod,
'id_schedule' => $this->id_schedule,
'id_detail_order' => $this->id_detail_order,
'prod_qty' => $this->prod_qty,
'scan_quantity' => $this->scan_quantity,
]);
$query->andFilterWhere(['like', 'id_assy', $this->id_assy])
->andFilterWhere(['like', 'barcode_kanban', $this->barcode_kanban])
->andFilterWhere(['like', 'barcode_group', $this->barcode_group]);
return $dataProvider;
}
It alwasy getting unknwon property ::id_order.
$query->andFilterWhere(['order_project.id_order' => $this->id_order])
And it also error when I call property from relations.
Please help me…
Thank you…