doudie2693 2015-06-12 09:01
浏览 52

使用Propel Versionable时,在模型中调用save()

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条回答 默认 最新

  • dpu66046 2015-08-02 18:12
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源