Hi Bart, having `children` the same type as the parent starts an endless recursion ( children like create another children which will create another and so on ). Easiest way to address this (tho maybe not optimal) is to create another definition for the nested type.
On Jun 17, 9:02 am, Bart <blauw...@gmail.com> wrote: > Hi everyone. > > I'm having a rather odd problem which I suspect is either a bug or > more likely I'm trying to do things the wrong way.I'd appreciate if > you can shed a little light on the proper way to address this. Let me > describe the issue. > > We have a container with the following ORM definition: > Container: > type: entity > table: container > id: > id: > type: integer > generator: > strategy: AUTO > fields: > name: > type: string > length: 25 > oneToMany: > children: > targetEntity: Container > mappedBy: parent > manyToOne: > parent: > targetEntity: Container > inversedBy: children > joinColumn: > name: parent_id > referencedColumnName: id > > And a FormType which looks as follows: > use > Symfony\Component\Form\AbstractType, > Symfony\Component\Form\FormBuilder > ; > > class ContainerType extends AbstractType > { > public function buildForm(FormBuilder $builder, array $options) > { > $builder > ->add('name', 'text') > ->add('children', 'collection', array( > 'type' => new ContainerType(), > 'prototype' => false, > 'allow_add' => true, > 'allow_delete' => true, )); > > } > > } > > In the Controller we create a formBuilder by: > $data = new Container(); > $form = $this->get('form.factory')->create(new > ContainerType()); > $form->setData($data); > ....etc... > > The form will crash with a: > 'Fatal error: Maximum function nesting level of '100' reached, > aborting! in /app/cache/dev/twig/15/ff/ > 401ed143a10a78a26e39b6e98c03.php on line 38' > And a long stack trace showing the form recursing on itself. > > I looked at the code and I didn't see an easy way to stop the > Container from rendering an infinite depth. What I'd really want is > for it to throw out all the existing children from a parent but when a > child does not exist not to create a prototype one.... > > Obviously the buildForm method calls "new ContainerType" so that would > be at the root of the issue. However I can't seem to pass > "\ContainerType" as type. > > Can anyone shed a light on the correct way to do this? > > Thanks! -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en