We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

ORM doesn't see changes

  1. Begin transaction
  2. Update model - OK
  3. Update model again (without commit) - changes are not visible

this is serious problem, see simple example

function afterUpdate () {

  if (!$this->is_delivered) {

    $this->is_delivered = true;
    $this->update(); // THIS LOOPS FOREVER! 

  }

}

You may ask why don't You change it in beforeUpdate() but it is not that simple, above is just illustration of a problem.

I've tryied $this->refresh() - no effect, $this->reset() doesn't help either. It's a serious problem for me, and I guess it might be for many ppl out there.

Is there ANY way for it to see changes?

To be honest it looks like huge/serious bug/problem of Phalcon ORM.

Changing $this->update() to $this->save() resolved the problem,

edited Oct '19

Hmm... why did u use afterUpdate event? Is it possible before that, so u dont need second save. (just is not good idea (not recommended) to place save/update to same element in event)

function beforeUpdate() {
    if (!$this->is_delivered) {
        $this->is_delivered = true;
    }
}

Or... on before validation... depends of situation

function beforeValidation() {
    if (!$this->is_delivered) {
        $this->is_delivered = true;
    }
}

I've already explainded it in the 1st post:

You may ask why don't You change it in beforeUpdate() but it is not that simple, above is just illustration of a problem.

It's just complicated system, and it's very inconvenient for me to do it before update, anyway, problem solved with save() inside afterUpdate() instead of update()

What phalcon version?

edited Oct '19

Also it shouldn't really matter if you are doing save or update, update calls save anyway.

Maybe you have some custom login in update or save method?

edited Oct '19

Phalcon ver 3.4.4

I don't get the login thing, I'm just starting DB transaction (PostgreSQL), and operate on many models, quite complicated algorithm.

Anyway at some point, within the same transaction, after updating one of entities, sometimes I must update it again in afterUpdate() method, but when it recursively fires afterUpdate() again on the same object, if I use update(), it doesn't see the change, like it's cached or something and loops forever.

Using save() resolves the problem.