title: Symfony 3 expected "Doctrine\Common\Collections\ArrayCollection" given ... when using OneToMany
body: <p>I have a problem with this error:</p>
  
  <pre><code>Expected argument of type "AppBundle\Entity\BusVehiclesAmenities", "Doctrine\Common\Collections\ArrayCollection" given
  </code></pre>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>After few comments I applied suggestions and error is gone now (remove ArrayCollection from bus vehicles amenities Entity, removed setting bus vehicles amenities entity from controller and removed ORM Join columns on all mapped entites)</p>
  
  <p>Now I have this error:</p>
  
  <pre><code>The association AppBundle\Entity\BusVehiclesAmenities#bus refers to the inverse side field AppBundle\Entity\BusVehicles#busVehiclesAmenities which does not exist.
  </code></pre>
  
  <p>Mapped entities</p>
  
  <p>Bus vehicles:</p>
  
  <pre><code>/* @ORM\OneToMany(
       *     targetEntity="BusVehiclesAmenities",
       *     mappedBy="bus",
       *     fetch="EXTRA_LAZY",
       *     orphanRemoval=true,
       *     cascade={"persist"}
  
       * )
       *
       */
  
      private $busVehiclesAmenities;
  </code></pre>
  
  <p>bus vehicles amenities entity:</p>
  
  <pre><code>private $bus;
  
      /**
       *
       * @ORM\ManyToOne(targetEntity="Amenities", inversedBy="amenities")
       * @ORM\JoinColumn(name="amenities_id", referencedColumnName="id")
       *
       */
  </code></pre>
  
  <p>I am using Collection of Forms to create OneToMany relationship. Problem is when I adding new data I got this error.</p>
  
  <p>Does someone knows where is the problem?</p>
  
  <p>CODE:
  Bus Entity (Parent)</p>
  
  <pre><code>/**
       * @ORM\OneToMany(targetEntity="BusVehiclesAmenities", mappedBy="bus", cascade={"persist", "remove"}, fetch="EAGER", orphanRemoval=true)
       * @ORM\JoinColumn(name="bus_id", referencedColumnName="id", onDelete="CASCADE")
       *
       */
  
  private $busVehiclesAmenities;
  
      public function __construct()
      {
  
          $this-&gt;busVehiclesAmenities = new ArrayCollection();
      }
  
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Add busVehiclesAmenities
       *
       * @param \AppBundle\Entity\BusVehiclesAmenities busVehiclesAmenities
       * @return BusVehicles
       */
      public function addBusVehiclesAmenities(BusVehiclesAmenities $busVehiclesAmenities)
      {
  
           if ($this-&gt;busVehiclesAmenities-&gt;contains($busVehiclesAmenities)) {
               return;
           }
          $this-&gt;busVehiclesAmenities-&gt;add($busVehiclesAmenities);
          $busVehiclesAmenities-&gt;addBus($this);
  
          return $this;
      }
  
      /**
       * Set busVehiclesAmenities
       *
       * @param \AppBundle\Entity\BusVehiclesAmenities busVehiclesAmenities
       * @return BusVehicles
       */
      public function setBusVehiclesAmenities(BusVehiclesAmenities $busVehiclesAmenities)
      {
  
           $this-&gt;busVehiclesAmenities = $busVehiclesAmenities;
  
          return $this;
      }
  
      /**
       * Remove busVehiclesAmenities
       *
       * @param \AppBundle\Entity\BusVehiclesAmenities $busVehiclesAmenities
       * @return BusVehicles
       */
      public function removeBusVehiclesAmenities(BusVehiclesAmenities $busVehiclesAmenities)
      {
          if (!$this-&gt;busVehiclesAmenities-&gt;contains($busVehiclesAmenities)) {
              return;
          }
          $this-&gt;busVehiclesAmenities-&gt;removeElement($busVehiclesAmenities);
          $busVehiclesAmenities-&gt;removeBus($this);
  
          return $this;
  
  
  
      }
  </code></pre>
  
  <p>Amenity Entity (Child)</p>
  
  <pre><code>/**
       *
       * @ORM\ManyToOne(targetEntity="BusVehicles", inversedBy="busVehiclesAmenities")
       * @ORM\JoinColumn(name="bus_id", referencedColumnName="id")
       *
       */
      private $bus;
  
      public function __construct()
      {
          $this-&gt;bus = new ArrayCollection();
      }
  
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
  
      /**
       * @param BusVehicles $busVehicles
       */
  
      public function addBus(BusVehicles $busVehicles)
      {
          if ($this-&gt;bus-&gt;contains($busVehicles)) {
              return;
          }
          $this-&gt;bus-&gt;add($busVehicles);
          $busVehicles-&gt;addBusVehiclesAmenities($this);
      }
  
      /**
       * @param BusVehicles $busVehicles
       */
      public function removeBus(BusVehicles $busVehicles)
      {
          if (!$this-&gt;bus-&gt;contains($busVehicles)) {
              return;
          }
          $this-&gt;bus-&gt;removeElement($busVehicles);
          $busVehicles-&gt;removeBusVehiclesAmenities($this);
      }
  </code></pre>
  
  <p>EDIT 1:</p>
  
  <p>I removed ArrayCollection from BusVehiclesAmenitites Entity but I still got same error when I submit form.</p>
  
  <p>EDIT 2:</p>
  
  <p>Added forms</p>
  
  <p>BusVehicles Form Type</p>
  
  <pre><code>&lt;?php
  
  namespace AdminBundle\Form\Type;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  
  
  
  
  class BusVehiclesType extends AbstractType
  {
      /**
       * {@inheritdoc}
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('licencePlate')
              -&gt;add('chassisNumber')
              -&gt;add('manufacturer')
              -&gt;add('busVehiclesAmenities', CollectionType::class, array(
                  'entry_type'   =&gt; BusVehiclesAmenitiesType::class,
                  'prototype' =&gt; true,
                  'allow_add' =&gt; true,
                  'allow_delete' =&gt; true,
                  'by_reference' =&gt; false,
              ));
      }
  
      /**
       * {@inheritdoc}
       */
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'AppBundle\Entity\BusVehicles',
              'cascade_validation' =&gt; true,
  
          ));
      }
  
      /**
       * {@inheritdoc}
       */
      public function getBlockPrefix()
      {
          return 'adminbundle_busvehicles';
      }
  
  
  }
  </code></pre>
  
  <p>BusVehiclesAmenities Form Type</p>
  
  <pre><code>    &lt;?php
  
  namespace AdminBundle\Form\Type;
  
  use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\Extension\Core\Type\NumberType;
  use Symfony\Component\Form\FormBuilderInterface;
  use AppBundle\Entity\BusVehiclesAmenities;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  
  
  class BusVehiclesAmenitiesType extends AbstractType
  {
      /**
       * {@inheritdoc}
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('price', NumberType::class, array(
  
              ))
              -&gt;add('amenities', EntityType::class, array(
                  'class' =&gt;'AppBundle:Amenities',
                  'choice_label' =&gt; 'name',
              ))
  
          ;
  
      }
  
      /**
       * {@inheritdoc}
       */
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; BusVehiclesAmenities::class
          ));
      }
  
      /**
       * {@inheritdoc}
       */
      public function getBlockPrefix()
      {
          return 'appbundle_busvehiclesamenities';
      }
  
  
  }
  </code></pre>
  
  <p>Controller.</p>
  
  <pre><code>/**
       * @Template
       */
      public function newAction(Request $request)
      {
          $bus = new BusVehicles();
          $busAmenities = new BusVehiclesAmenities();
          //   $this-&gt;getDoctrine()-&gt;getManager()-&gt;persist($busAmenities);
          $bus-&gt;setBusVehiclesAmenities($busAmenities);
          $form = $this-&gt;createForm(BusVehiclesType::class, $bus);
          $form-&gt;handleRequest($request);
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
  
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              /*$form-&gt;get('busVehiclesAmenities')-&gt;getData()-&gt;map(
                  function ($amenities) use ($em, $bus) {
  
                      $bus-&gt;setBusVehiclesAmenities($amenities);
                      $em-&gt;persist($amenities);
                  }
              );*/
              $em-&gt;persist($bus);
  
              $em-&gt;flush();
  
              // Adding flash message to our user
  
              $this-&gt;addFlash('success', 'admin.bus.created');
  
  
              //  return $this-&gt;redirectToRoute('bus_add');
  
          }
          return [
              'form' =&gt; $form-&gt;createView(),
          ];
      }
  </code></pre>