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.
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
I've tried this, but the joins don't seem to be... joining.
$this->db->join('users s','ati.time_index_user_id = s.user_id');
$this->db->join('attendance_code_groups acg', 's.user_attendance_code_group = acg.group_id');
$this->db->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->db->where('s.user_id', 123);
$this->db->update('attendance_time_index ati');
Any ideas?