CodeIgniter Forums
active record bug: count_all() does not reset where() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: active record bug: count_all() does not reset where() (/thread-23135.html)



active record bug: count_all() does not reset where() - El Forum - 10-01-2009

[eluser]Bramme[/eluser]
Code:
// amount of updates
$this->db->where('story_id', $story_id);
$updates = $this->db->count_all('sd_story_updates');
$update_no = $updates + 1;

// update story with correct number of updates
$this->db->where('id', $story_id);
$this->db->update('sd_stories', array('parts' => $update_no));

produces this query: "UPDATE `sd_stories` SET `parts` = 1 WHERE `story_id` = '3' AND `id` = '3'"

Not really wanted behavior.


active record bug: count_all() does not reset where() - El Forum - 10-14-2009

[eluser]khagendra[/eluser]
Please check $active_record in config/database.php. it should be like this
$active_record = TRUE;

perhaps it may be ok.

please once do like this
Code:
function test1($story_id)
{
  $this->db->where('story_id', $story_id);
  $updates = $this->db->count_all('sd_story_updates');
  $update_no = $updates + 1;
  return $update_no;
}

function test2($story_id, $update_no)
{
  $this->db->where('id', $story_id);
  $this->db->update('sd_stories', array('parts' => $update_no));
}
define two different function(here test1 and test2)in model. get the return value from one model function (here test1). then pass this value to other model function (here test2).

hope u understand it.