2010-08-10 38 views
1

我有兩個關係一對多的類。我想製作一個嵌套表單來輸入一個對象和一些與之相關的對象。symfony:問題與方法'embedRelation'

但是,當我保存表格時,引用我的主類的關鍵字不是用主類的關鍵字更新的。但其他鍵已創建。

我的架構:

Enfant: 
    connection: doctrine 
    tableName: enfant 
    columns: 
    id: 
     type: integer(2) 
     fixed: false 
     unsigned: true 
     primary: true 
     autoincrement: true 
    nudparent: 
     type: string(20) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    relations: 
    Locataire: 
     local: nudparent 
     foreign: nud 
     type: one 
Locataire: 
    connection: doctrine 
    tableName: locataire 
    columns: 
    nud: 
     type: string(20) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: false 
    nbenfants: 
     type: integer(1) 
     fixed: false 
     unsigned: true 
     primary: false 
     notnull: false 
     autoincrement: false 
    relations: 
    Bail: 
     local: nud 
     foreign: locataire 
     type: many 
    Enfant: 
     local: nud 
     foreign: nudparent 
     type: many 
    Refus: 
     local: nud 
     foreign: nud 
     type: many 

,使形式:

$subForm = new sfForm(); 
for ($i = 0; $i < 2; $i++) 
{ 
    $enfant = new Enfant(); 
    $enfant->Locataire = $this->getObject(); 

    $form = new EnfantForm($enfant); 

    $subForm->embedForm($i, $form); 
} 
$this->embedForm('new', $subForm); 
+0

你可以發佈Locataire模式嗎。 – johnwards 2010-08-10 10:01:54

+0

+1,我有許多形式相同的問題,我必須做一些像「parent-> setChild($ child);」並再次保存父母以使其工作。我認爲如果孩子引用父母而不是其他方式,這種自動保存功能就可以工作。 – greg0ire 2010-08-10 10:12:28

+0

@johnwards:我已經發布Locataire架構,我沒有看到你想要的... @gregOire:在教程中,我已經看到我們可以做到這一點,但是當我做同樣的事情時, t工作 – Elorfin 2010-08-10 11:16:13

回答