2012-01-12 43 views
0

這裏的情況是:Symfony的1.4形式不保存外鍵與embedRelation

我有A型和B模型模型A對模型B

外鍵(modelb_id)

兩種型號都有自己的形式。我嵌入模型B的形式進入的形式A.

class ModelAForm extends ....{ 

    public function configure(){ 
    unset($this['modelb_id']); 
    $this->embedRelation('ModelB'); 
    } 
} 

問題:

當我保存的形式,它不保存ModelB,但它不會改變的價值ModelA中的外鍵(在模型A中,modelb_id仍爲空)。

任何人都有線索?

回答

0

我一直與embedRelation()問題,直到我發現了一個名爲ahDoctrineEasyEmbeddedRelationsPlugin插件,它解決了ALL我的嵌入問題與形式。

我認爲最好使用這個插件比調試你的嵌入反覆。 :)

0

如果要更新一個窗體的保存相關對象。您可以重寫BasesfForm :: doUpdateObject方法。

在你Form.class.php,添加類似:

/* If you want to add some logic before updating or update other associated 
    * objects, this is the method to override. 
    * 
    * @param array $values An array of values 
    */ 
    public function doUpdateObject($values) { 
    // Handle the normal stuff that this method does 
     $this->getObject()->fromArray($values, BasePeer::TYPE_FIELDNAME); 
     $obj = $this->getObject(); 

    // and, get the needed value 
     $val = $obj->getDesiredPropertyValue(); 

    // use the value to update the related thing 
     foreach ($obj->getRelatedObjects() as $related) 
      { 
       $related->setColumnNamedThing($val); 
      } 
    } 
相關問題