3

The Setup

I am working on a project using Symfony 3 and SonataAdminBundle 3.1.

I am using the nested form method of sonata admin where I have 4 entities:

Category, Product, Supplier, and Contact. They all have one-to-many relation with each other respectively.

I am using sonata_type_collection to put products in category form, and using the same to put suppliers in product form, and using the same to put contacts in the supplier form. The contact form has a sonata_type_model_list field for zipcodes.

The Problem

I am facing the following error when I click the add new contact button on the supplier form from within the category > product form.

Could not get element id from s58c147845272f_products_2_suppliers_0_contacts Failing part: contacts

The error does not show up when I save the form step by step - like i add a product to the category form then save the form, then add a supplier to product and then save the form, and when i add the contact - the contact form is loaded and the above mentioned exception is not thrown. Also When I go directly to Supplier form and add the contact there, the exception is not thrown.

It is only when the supplier is not saved from within the category form that the above exception is thrown.

any help is highly appreciated.

dagger
  • 515
  • 2
  • 6
  • 17
  • AFAIK sonata admin dosen't support more than one level of nested collections.Show your entity mapping so we can help you further – Mawcel Mar 10 '17 at 10:14
  • I'm facing the same issue. There must be a way around that. @Mawcel are you sure there is no support for multi-level nested collections? – RaphArbuz Jul 31 '17 at 22:01
  • Apparently it is now supported but i'm not aware of the details as i'm not currently working on a sonata based project these days.Have a look here: https://github.com/sonata-project/SonataAdminBundle/pull/3553 – Mawcel Aug 01 '17 at 14:58

1 Answers1

2

Check if any of your properties have underscore in the name, like my_file. Try to change it into myFile and also accordingly change code in your Admin class: $formMapper->add('my_file', 'file'); => $formMapper->add('myFile', 'file');.

Update:

I think I know what it is specifically - you probably have reference to your parent in your children. If that's the case, then add in your Admin classes for entities that have reference to the parents:

    $formMapper->add('[parent_reference_attribute]', 'sonata_type_model_hidden');

Replacing [parent_reference_attribute] with name of your field referencing the parent.

Then exception should be gone, at least it was in my case.

Łukasz Zaroda
  • 869
  • 2
  • 19
  • 55