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

multiple model object update doesn't work properly

So we try to update a fiend of a model object twice after the object is loaded, and the second update doesn't work while it returns true.

// initial status value in db: 0

$Account->setStatus(1);

if ($Account->update() !== false) {

print "update done!";

}

$Account->setStatus(2);

if ($Account->update() !== false) {

print "update done!";

}

please note that $this->useDynamicUpdate(true); for this model, and when useDynamicUpdate is turned false, it works without any problem.

so basically to summarize it:

with $this->useDynamicUpdate(true);

  • initial value: 0
  • after first update: 1
  • after second update: 1

with $this->useDynamicUpdate(false);

  • initial value: 0
  • after first update: 1
  • after second update: 2


3.2k

We had the same problem when migrating to useDynamicUpdate(true).

We solved it by using an afterUpdate hook on every model.

/**
  • ORM hook fired after a model was updated */ protected function afterUpdate() { // We need to update the snapshot so that change -> save -> change -> save on a model instance would work $this->setSnapshotData($this->toArray()); }