Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Model not update twice
  • Hello,

    When I updated an OrmModel attribute at first time, I get is_changed() to True and save() update my database. After I do some delayed actions and I need to change again the same attributes with an other value, but I obtain is_changed() to false and save() do nothing but when I dump the OrmModel, the value is modified in lmemory. I there an method to force un clean the record or another soluce ??

    $myModel->save();  // is OK
    << actions >>
    $myModel->save();  // do nothing on database


  • Which Fuel version?
  • Version 1.8
  • I can't reproduce it in 1.9-dev. My test code:

    // create test data
    $query = DB::insert('test', array('name'))->values(array('Name'))->execute();

    // get the record
    $test = Model_Test::query()->select('id', 'name')->where('id', 1)->get_one();

    \Debug::dump($test->is_changed()); // should be False

    $test->name = 'New name';

    \Debug::dump($test->is_changed()); // should be True


    \Debug::dump($test->is_changed()); // should be False

    $test->name = 'Other name';

    \Debug::dump($test->is_changed()); // should the True


    The database profiler shows me it executes:

    INSERT INTO `test` (`name`) VALUES ('Name')
    SELECT `t0`.`id` AS `t0_c0`, `t0`.`name` AS `t0_c1` FROM `test` AS `t0` WHERE `t0`.`id` = 1 LIMIT 1
    UPDATE `test` SET `name` = 'New name' WHERE `id` = 1
    UPDATE `test` SET `name` = 'Other name' WHERE `id` = 1

    I have also tested this with 1.8.0, witht he same result.

    So no problems here?
  • Hum ... !!!

    I've spend time before post without find a mistake. So, I will check tonight again and use profiler so by using your method. Perharps  'gremlins' are hidden very well.

    Thanks Harron

  • If you Debug::dump() the object before the save(), check the values of _data and _original. 

    is_changed() compares the two to see if there is something that needs saving. Also, after a save(), _data and _original should be in sync.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion