title: Convert MySql query containing case statement to codeigniter active record query
body: <p>I have the following query which I want to make more Codeigniter Active Record friendly but I'm not sure how to go about adding case statements to the set part of the query.</p>
  
  <pre><code>UPDATE attendance_time_index ati
  JOIN users s ON ati.time_index_user_id = s.user_id
  JOIN attendance_code_groups acg ON s.user_attendance_code_group = acg.group_id
  SET ati.time_index_default = CASE WHEN ati.time_index_value = 'PM' THEN acg.group_pm_default ELSE acg.group_am_default END
  WHERE s.user_id = 123
  </code></pre>
  
  <p>I've tried this, but the joins don't seem to be... joining.</p>
  
  <pre><code>$this-&gt;db-&gt;join('users s','ati.time_index_user_id = s.user_id');
  $this-&gt;db-&gt;join('attendance_code_groups acg', 's.user_attendance_code_group = acg.group_id');
  $this-&gt;db-&gt;set('ati.time_index_default', 'CASE WHEN ati.time_index_value = 'PM' THEN acg.group_pm_default ELSE acg.group_am_default END', FALSE);
  $this-&gt;db-&gt;where('s.user_id', 123);
  $this-&gt;db-&gt;update('attendance_time_index ati');
  </code></pre>
  
  <p>Any ideas?</p>