1

1対多の関係を持つ2つのクラスがあります。そして、オブジェクトとそれにリンクされている他のオブジェクトを入力するネストされたフォームを作成したいと考えています。

しかし、フォームを保存すると、メイン クラスを参照するキーがメイン クラスのキーで更新されません。ただし、他のキーは作成されます。

私のスキーマ:

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);
4

1 に答える 1

0

埋め込み関係を使用する必要があります。ここで詳細と例を見つけることができます: http://prendreuncafe.com/blog/post/2009/11/29/Embedding-Relations-in-Forms-with-Symfony-1.3-and-Doctrine

于 2011-02-17T16:04:15.500 に答える