2
votes

My Problem: I cannot get an associated Entity to save using the entity field type or collection field type.

My Database Relations My Database Relations

Database Structure Description:

  • I have a 'Usage' entity that has many 'telephone numbers' attached to it.
  • Each 'telephone number' has one and only one region.




What I want to Achieve

  • On my edit 'Usage' form I want to display a dropdown box for each 'telephone number' that the 'Usage' already has attached to it.

  • Each dropdown box will list all the telephone numbers for that region, allowing the user to select a new telephone number

enter image description here

How I want to display my Usage Form


What I want to display

My Controller

My Entities

Form Type

Twig Template

ViewTransformer

ObjectToArrayTransformer

My Problem: When I submit the form, nothing happens, the new telephone number I selected is not persisted.

1

1 Answers

2
votes

I think your problem is that in your Usage Entity, you don't cascade the persist operation. You should try this :

@ORM\OneToMany(targetEntity="Telephone", mappedBy="usage", cascade={"persist"})

Hope this helps