2011-05-18 52 views
3

我在我的模式中有一個可版本化的表。例如,當我更改狀態時,我希望它不被版本化,但當我更改shippingPrice時,版本已更新。Symfony原則versionnable行爲忽略字段

MyOrder: 
    actAs: 
    Timestampable: 
    Versionable: 
     versionColumn: version 
     className: %CLASS%Version 
     auditLog: true 
    columns: 
     userId: { type: integer, notnull: true } 
     status: {type: enum, values: ["status1", "status2"]} 
     shippingPrice: { type: float, notnull: true } 
     #more columns 

我該怎麼做?

+0

好問題! – ybull 2011-05-19 16:37:50

回答

0

這有點不好意思,但應該做我認爲需要的。

我還沒有測試過,但我的理解是,如果你做了一個dql update(),則不會觸發Versionable。

像這樣

$result = $this->createQuery() 
      ->update('MyOrder m') 
      ->set('m.status', $var) 
      ->execute(); 

但是,如果您檢索對象,改變它,從而節省:

$m = MyOrderTable::getInstance()->findOneById($id); 
$m->setShippingPrice($price); 
$m->save(); 

然後版本可控就會被觸發,所以你應該得到一個新的版本。

所以你可以用它來解決這個問題。