Call save() in model while using Propel Versionable

89 views Asked by At

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?

1

There are 1 answers

0
halfer On

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).