title: Symfony 3: allow_delete in Forms not working
body: <p>I have a problem with my form in Symfony 3. I have <strong>one-to-many-to-one join</strong> (Doctrine 2). It handles Orders (<strong>Order</strong>), Products (<strong>Product</strong>) and joining entity (<strong>OrderProduct</strong>), which holds amount of product in order.</p>
  
  <p>I have a <strong>form</strong> for <strong>add and update</strong> order entries, which uses <strong>Collection of OrderProducts</strong>. It's all based on documentation (<a href="https://symfony.com/doc/current/form/form_collections.html" rel="nofollow noreferrer">link</a>).</p>
  
  <p>In the form I have a <strong>button for add a product</strong> (from documentation, adds a &lt;li&gt; to DOM) and every added has a <strong>button for remove it</strong> (from documentation, removes &lt;li&gt; from DOM). This part is working - adding to and removing from DOM.</p>
  
  <p>Adding products works (as at the new order, than when editting). </p>
  
  <p>But my problem is with removing. Products which was <strong>succesfully deleted from form</strong>, are <strong>still appearing</strong> in <em>$editForm->getData()</em>.</p>
  
  <p><strong>OrderProduct Form</strong>
      
  
  <pre><code>namespace AppBundle\Form;
  
  use AppBundle\Entity\ProductType;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  
  class OrderProductType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('amount')
              -&gt;add('product')
          ;
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults(
              array(
                  'data_class' =&gt; 'AppBundle\Entity\OrderProduct',
              )
          );
      }
  
      public function getName()
      {
          return 'app_bundle_order_product_type';
      }
  }
  </code></pre>
  
  <p><strong>Order Form</strong>
      
  
  <pre><code>namespace AppBundle\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  
  class OrderType extends AbstractType
  {
  
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('customer')
              -&gt;add('date', null, array('widget' =&gt; 'single_text'))
              -&gt;add('payment', null, array('widget' =&gt; 'single_text'))
              -&gt;add('processed', null, array('widget' =&gt; 'single_text'))
              -&gt;add(
                  'orderProducts',
                  CollectionType::class,
                  array(
                      'entry_type'    =&gt; OrderProductType::class,
                      'allow_add'     =&gt; true,
                      'allow_delete'  =&gt; true,
                      'by_reference'  =&gt; false,
                      'prototype'     =&gt; true,
                      'delete_empty'  =&gt; true,
                      'entry_options' =&gt; array('data_class' =&gt; 'AppBundle\Entity\OrderProduct'),
                  )
              );
  
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
      }
  
      public function getName()
      {
          return 'app_bundle_order_type';
      }
  
  }
  </code></pre>
  
  <p><strong>Current action in OrderController</strong>
  <em>(Adding product works, removing not)</em>
      public function editAction (Request $request, $orderId) {</p>
  
  <pre><code>    $em = $this-&gt;getDoctrine()-&gt;getManager();
      $order = $em-&gt;getRepository('AppBundle:Order')-&gt;find($orderId);
  
      if (!$order) {
          throw $this-&gt;createNotFoundException('No order found for id '.$orderId);
      }
  
      $editForm = $this-&gt;createForm(OrderType::class, $order);
      $editForm-&gt;add('submit', SubmitType::class);
  
      $editForm-&gt;handleRequest($request);
  
      if ($editForm-&gt;isSubmitted() &amp;&amp; $editForm-&gt;isValid()) {
  
          $order = $editForm-&gt;getData();
  
          //print '&lt;pre&gt;';
          //var_dump($order-&gt;getOrderProducts());
          //die();
  
          $orderProducts = $order-&gt;getOrderProducts();
  
          $em-&gt;persist($order);
  
          foreach ($orderProducts as $oneOrderProduct) {
              $oneOrderProduct-&gt;setOrder($order);
              $em-&gt;persist($oneOrderProduct);
          }
  
          //print '&lt;pre&gt;';
          //var_dump($order-&gt;getOrderProducts());
          //die();
  
          $em-&gt;flush();
  
          return $this-&gt;redirectToRoute('one_order', array('orderId' =&gt; $order-&gt;getId()));
      }
  
  
      return $this-&gt;render(
          'order/new.html.twig', array(
          'form' =&gt; $editForm-&gt;createView(),
      ));
  
  }
  </code></pre>
  
  <p>I know that I must remove removed OrderProducts from Order in editAction, but now I can't, because from the form is sent all OrderProducts.</p>
  
  <p><strong>Order Entity</strong>
      
  
  <pre><code>namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  use Doctrine\Common\Collections\ArrayCollection;
  use AppBundle\Entity\OrderProduct;
  use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="order_")
   */
  class Order
  {
  
      /**
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
      /**
       * @ORM\ManyToOne(targetEntity="Customer", inversedBy="orders")
       * @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
       */
      private $customer;
      /**
       * @ORM\Column(type="date")
       */
      private $date;
      /**
       * @ORM\Column(type="date")
       */
      private $payment;
      /**
       * @ORM\Column(type="date")
       */
      private $processed;
  
      public function __toString()
      {
          return strval($this-&gt;getId());
      }
  
      /**
       * @ORM\OneToMany(targetEntity="OrderProduct", mappedBy="order")
       */
      private $orderProducts;
  
      public function __construct()
      {
          $this-&gt;orderProducts = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set date
       *
       * @param \DateTime $date
       *
       * @return Order
       */
      public function setDate($date)
      {
          $this-&gt;date = $date;
  
          return $this;
      }
  
      /**
       * Get date
       *
       * @return \DateTime
       */
      public function getDate()
      {
          return $this-&gt;date;
      }
  
      /**
       * Set payment
       *
       * @param \DateTime $payment
       *
       * @return Order
       */
      public function setPayment($payment)
      {
          $this-&gt;payment = $payment;
  
          return $this;
      }
  
      /**
       * Get payment
       *
       * @return \DateTime
       */
      public function getPayment()
      {
          return $this-&gt;payment;
      }
  
      /**
       * Set processed
       *
       * @param \DateTime $processed
       *
       * @return Order
       */
      public function setProcessed($processed)
      {
          $this-&gt;processed = $processed;
  
          return $this;
      }
  
      /**
       * Get processed
       *
       * @return \DateTime
       */
      public function getProcessed()
      {
          return $this-&gt;processed;
      }
  
      /**
       * Set customer
       *
       * @param \AppBundle\Entity\Customer $customer
       *
       * @return Order
       */
      public function setCustomer(\AppBundle\Entity\Customer $customer = null)
      {
          $this-&gt;customer = $customer;
  
          return $this;
      }
  
      /**
       * Get customer
       *
       * @return \AppBundle\Entity\Customer
       */
      public function getCustomer()
      {
          return $this-&gt;customer;
      }
  
      /**
       * Add orderProduct
       *
       * @param \AppBundle\Entity\OrderProduct $orderProduct
       *
       * @return Order
       */
      public function addOrderProduct(\AppBundle\Entity\OrderProduct $orderProduct)
      {
          $this-&gt;orderProducts[] = $orderProduct;
  
          return $this;
      }
  
      /**
       * Remove orderProduct
       *
       * @param \AppBundle\Entity\OrderProduct $orderProduct
       */
      public function removeOrderProduct(\AppBundle\Entity\OrderProduct $orderProduct)
      {
          $this-&gt;orderProducts-&gt;removeElement($orderProduct);
      }
  
      /**
       * Get orderProducts
       *
       * @return \Doctrine\Common\Collections\Collection
       */
      public function getOrderProducts()
      {
          return $this-&gt;orderProducts;
      }
  }
  </code></pre>
  
  <p>But in POST it's OK <a href="https://i.stack.imgur.com/s05kV.png" rel="nofollow noreferrer">as you can see here</a>, here I removed 2 of 4 products. Problem appears in form handling.</p>