Hi,
I have these two tables "episodes" and "seasons":
Seasons id number Episodes id number season_id code
So, a season can have many episodes.
In grocery crud I set this:
$crud->display_as('number', 'Episode number'); $crud->set_relation('season_id', 'seasons', 'number'); $crud->display_as('season_id', 'Season number');
And now I would be able to update the "code" column with a callback, combining the Season number and Episode number. This is what I did:
$crud->callback_before_insert(array($this, 'add_episode_code_callback')); $crud->callback_before_update(array($this, 'add_episode_code_callback')); function add_episode_code_callback($post_array) { $season_string = '' . $post_array['season_id']; if ($post_array['season_id'] < 10) { $season_string = '0' . $season_string; } $episode_string = '' . $post_array['number']; if ($post_array['number'] < 10) { $episode_string = '0' . $episode_string; } $post_array['code'] = 'S' . $season_string . 'E' . $episode_string; return $post_array; }
The problem is that it uses the season_id value instead of the "number" value from the seasons table.
Is this possible to achieve somehow?