Calling save () on a model when using Propel Versionable

I just switched an existing model as Versionable

.

After debugging quite a bit, I now realized that there are quite a few cases where I use $this->save()

multiple times in a model and that this is finally causing duplicate entries in the Versions table.

This is the only way to prevent this by removing the methods -save()

from the model (I tried this, it works) or is there another, simpler way to prevent the inner loop while creating the version and saving it

+3


source to share


1 answer


Since you are not specifying the Propel version, I am assuming the stable version is 1.x, although the following may well apply to 2.x, which is in alpha5 at the time of writing.

According to this documentation, you can indicate when it is appropriate to save a new version of model strings using this method:

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

      



If this method returns false, the latest version is overwritten; if true, a new version is created.

(The docs are a bit wrong as I assume the parent should accept a parameter $con

: missing here, fixed).

+1


source







All Articles