I am using set_relation 1-n in combination with 'Where' and URL parameter.
Can't get it to work properly.
I had no problem with the set_relation until I was strting to use 'Where'.
When running this procedure I get the filtered result, but only for half a second, then the list is rebuilt, with no list records.
public function ny_nbc_match()
{
$crud = new grocery_crud();
$id = $_GET['lag'];
$crud->set_subject('match');
$crud->set_table('ny_nbc_match');
$crud->order_by('ny_nbc_match.ny_nbc_match_date','asc');
$crud->where('ny_nbc_match.ny_nbc_match_lag_id',$id);
$crud->display_as('ny_nbc_match_date','Matchdatum');
$crud->display_as('ny_nbc_match_season_id','Säsong');
$crud->display_as('ny_nbc_match_hall_id','Hall');
$crud->display_as('ny_nbc_match_lag_id','Lag');
$crud->required_fields('ny_nbc_match_date','ny_nbc_match_season_id','ny_nbc_match_lag_id','ny_nbc_match_hall_id');
$crud->set_relation('ny_nbc_match_lag_id','ny_nbc_lag','ny_nbc_lag_namn',null,'ny_nbc_lag_namn ASC');
$crud->set_relation('ny_nbc_match_season_id','ny_nbc_season','ny_nbc_season_namn',null,'ny_nbc_season_namn DESC');
$crud->set_relation('ny_nbc_match_hall_id','ny_nbc_hallar','ny_nbc_hallar_namn',null,'ny_nbc_hallar_namn ASC');
$output = $crud->render();
$this->_example_output($output);
}
If I hardcode the filter value in Where, the list is shown, filtered according to the hardcoded value.
$crud->where('ny_nbc_match.ny_nbc_match_lag_id',2);
If I keep the $id variable in the where-clause and disable the set_relation on ny_nbc_lag, the filter works, no "auto-refresh" that removes the list after a half second. But, of course without any relation to that table that I need
$crud->where('ny_nbc_match.ny_nbc_match_lag_id',$id);
...
// $crud->set_relation('ny_nbc_match_lag_id','ny_nbc_lag','ny_nbc_lag_namn',null,'ny_nbc_lag_namn ASC');
I realize that I have to do some filtering (where) in the set_relation as well. But I don't know how. I have tried to add this filter in the set_relation but without any affect on the result.
Other thing about this, the sort order on the "set_relation('ny_nbc_match_lag_id','ny_nbc_lag','ny_nbc_lag_namn',null,'ny_nbc_lag_namn ASC');"
seems to override the sort order "$crud->order_by('ny_nbc_match.ny_nbc_match_date','asc');" in the list. Why?
Appreciate some help here