开发者

symfony : Problem with the method 'embedRelation'

开发者 https://www.devze.com 2023-01-10 18:12 出处:网络
I have two classes with a relation one-to-many. And I want to make a nested form to enter an object and some of others which are linked to it.

I have two classes with a relation one-to-many. And I want to make a nested form to enter an object and some of others which are linked to it.

But when I save the form, the key wich references my main class isn't update with the key of main class. However the other keys are created.

My schem开发者_JAVA技巧a :

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

And making form :

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


You need to use embedRelation. You can find more information and examples here: http://prendreuncafe.com/blog/post/2009/11/29/Embedding-Relations-in-Forms-with-Symfony-1.3-and-Doctrine

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号