• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
active record bug: count_all() does not reset where()

#1
[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.

#2
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.