I have a table bus_route It has the following rules
public function rules()
{
return [
[['schedule_id', 'stop_id'], 'required'],
[['schedule_id', 'stop_id', 'route_order', 'is_destination'], 'integer'],
[['departure_time'], 'safe']
];
}
stop_id
(foreign key) is the primary key (id) of table stops.
Now i want to display the stop_name
in stops
table for the corresponding stop_id
in bus route view. For that i added the following code in model
public function getStop()
{
return $this->hasOne(Stop::className(), ['id' => 'stop_id']);
}
and in view
'stop.stop_name',
Its working but the search function is not working for the stop name field. Other fields show a box to search where stop_id
field shows no box to search. How can i do a search for this field?
EDIT
BusrouteSearch.php
public function search($params)
{
$query = BusRoute::find();
$query->joinWith(['stop']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$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([
'id' => $this->id,
'schedule_id' => $this->schedule_id,
'departure_time' => $this->departure_time,
'stop_id' => $this->stop_id,
'route_order' => $this->route_order,
'is_destination' => $this->is_destination,
]);
return $dataProvider;
}