multi-select values disappear when record is set to published = 'no'
I'm using v 1.0 and my php version is 5.4.19.
I have a games_model in which the form_fields method contains a related 'prizes' field multi-select. The model is set up like this...class Client_games_model extends Base_module_model {
// some required fields here...
// foreign keys here...
public $has_and_belongs_to_many = array('prize_id' => 'prizes_to_client_games_model');
etc., etc..
prizes_to_client_games table in the db stores the game id and the prize id. Pretty straightforward.
Down in the form_fields method I set up the options and values like this...
$prizes_options = $CI->prizes_model->options_list('id', 'prize_name', array('published' => 'yes', 'client_id' => $client_id ), 'prize_name');
$prizes_values = (!empty($values['id'])) ? array_keys($CI->prizes_to_client_games_model->find_all_array_assoc('prize_id', array('game_id' => $values['id']))) : array();
$fields['prizes'] = array('label' => 'Prizes', 'type' => 'array', 'class' => 'add_edit prizes', 'options' => $prizes_options, 'value' => $prizes_values, 'mode' => 'multi');
The game also has a 'published' enum field and everything works perfectly as long as published is set to yes for the game itself. As soon as you set that to no, the prize values no longer show up in the selected values list on the right. What's weird is I can echo out the $prizes_values array and it works either way. The values are the same in the db as well. I've looked all through my code to see if there's some hidden little piece of code I've forgotten about that might be causing this but to no avail.
Is this something that you've encountered before?
Comments
Also, what is the $has_and _belongs_to_many property... did you mean $has_many? If so, you shouldn't need to create the form field since and retrieve the values and it will save it to the fuel_relationships table.
// set promoter prize selection area if( $user['super_admin'] == 'no') { // $client_id will have been set above $prizes_options = $CI->prizes_model->options_list('id', 'prize_name', array('published' => 'yes', 'client_id' => $client_id ), 'prize_name'); } else { $prizes_options = $CI->prizes_model->options_list('id', 'prize_name', array('published' => 'yes'), 'prize_name'); } $prizes_values = (!empty($values['id'])) ? array_keys($CI->prizes_to_client_games_model->find_all_array_assoc('prize_id', array('game_id' => $values['id']))) : array(); $fields['prizes'] = array('label' => 'Prizes', 'type' => 'array', 'class' => 'add_edit prizes', 'options' => $prizes_options, 'value' => $prizes_values, 'mode' => 'multi');
Thanks!