代码之家  ›  专栏  ›  技术社区  ›  Elorfin

symfony:embedRelation方法有问题

  •  1
  • Elorfin  · 技术社区  · 14 年前

    我有两门课,一对多有关系。我想做一个嵌套的表单来输入一个对象和其他一些链接到它的对象。

    但是当我保存表单时,引用我的主类的键并不是用主类的键更新的。但是其他的键被创建。

    我的架构:

    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);
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   Sergio    14 年前

    你需要使用嵌入关系。您可以在此处找到更多信息和示例: http://prendreuncafe.com/blog/post/2009/11/29/Embedding-Relations-in-Forms-with-Symfony-1.3-and-Doctrine