multi-select values disappear when record is set to published = 'no'

edited December 2013 in Bug Reports
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

  • edited 11:11AM
    So is the $prizes_values array value the same whether it's published or not and it's just not displaying correctly?

    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.
  • edited 11:11AM
    Right, it's just not displaying when the game is set to not published but the value of the variable is echoing out the same either way. I had set that up prior to switching over to 1.0 and never changed it. So, would there be a conflict there?
  • edited 11:11AM
    Actually, I have to associate this with a client_id so needed to control the options values. I hadn't included that part in the description above in an effort to keep things simple. Here's the actual setup...
    // 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');
  • edited 11:11AM
    I figured it out. There was a duplicate entry of the prizes field setup that was looking for published status of the game further down in the code. I had farmed this out to another dev earlier and it was a spaghetti mess when I got it back including some copied and pasted code. Geeez. The CMS was doing exactly what it was supposed to do.
    Thanks!
  • edited 11:11AM
    Great... glad you got it figured out.
Sign In or Register to comment.