Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call save() in model while using Propel Versionable

I just switched an existing Model to be Versionable.

After debugging quite a lot, I now realized that there are a quite a few cases that I use $this->save() in the model quite a few times and that this finally causing duplicate entries in the Version table.

Is the only way to prevent this by removing the -save() methods out of the model (I tried it out, it works) or is there another, more simple way to prevent the internal loop during version-creation and its saving?

like image 231
Steffen Brueckner Avatar asked Mar 08 '26 03:03

Steffen Brueckner


1 Answers

Since you don't specify a version of Propel, I'm assuming the stable version 1.x, though the following might well apply to 2.x, which is in alpha5 at the time of writing.

As per this documentation, you can specify when it is appropriate to save a new version of model rows using this method:

class Book extends BaseBook
{
  public function isVersioningNecessary($con = null)
  {
    return $this->getISBN() !== null && parent::isVersioningNecessary($con);
  }
}

If that method returns false, the last version is overwritten; if it is true, a new version is created.

(The docs are slightly wrong in that I assume the parent should take a $con parameter: missing there, fixed here).

like image 143
halfer Avatar answered Mar 10 '26 17:03

halfer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!