title: ORMInvalidArgumentException when trying to set related objects in Doctrine fixtures
body: <p>I'm new to Symfony and Doctrine. I have a few different entities that are related, but when I try to associate them in Fixtures I get an exception:</p>
  
  <blockquote>
    <p>Expected value of type "App\Entity\VehicleType" for association field "App\Entity\Make#$type", got "Doctrine\Common\Collections\ArrayColl<br>
      ection" instead.</p>
  </blockquote>
  
  <p>This seems to get thrown as soon as I call $manager->flush() in the second fixture. I used the entity generator to set these up and the relationships. Afterward I added JoinColumn to the ManyToOne annotations. These relationships are setup like this:</p>
  
  <pre><code>class VehicleType
  {
      /** 
       * @ORM\OneToMany(targetEntity="App\Entity\Make", mappedBy="type")
       */
      private $make;
  
      public function __construct()
      {   
          $this-&gt;make = new ArrayCollection();
      }   
  }
  
  class make
  {
  
      /**
       * @ORM\ManyToOne(targetEntity="App\Entity\VehicleType", inversedBy="make")
       * @ORM\JoinColumn(name="type", referencedColumnName="code")
       */
      private $type;
  
      public function __construct()
      {
          $this-&gt;type = new ArrayCollection();
      }
  }
  </code></pre>
  
  <p>And the fixtures look like this:</p>
  
  <pre><code>class VehicleTypeFixtures extends Fixture
  {
      public function load(ObjectManager $manager)
      {
          $vehicleTypesData = AppFixtures::loadJSON('vehicle_types.json');
  
          foreach($vehicleTypesData as $type) {
              $vehicleType = new VehicleType();
              $vehicleType-&gt;setCode($type-&gt;code);
              $vehicleType-&gt;setDescription($type-&gt;description);
              $manager-&gt;persist($vehicleType);
              $this-&gt;addReference('type-'.$type-&gt;code, $vehicleType);
          }
  
          $manager-&gt;flush();
      }
  }
  
  class MakeFixtures extends Fixture implements DependentFixtureInterface
  {
      public function load(ObjectManager $manager)
      {
          $makes = AppFixtures::loadJSON('makes.json');
  
          foreach($makes as $make) {
              $newMake = new Make();
              $newMake-&gt;setCode($make-&gt;code);
              $newMake-&gt;setDescription($make-&gt;description);
  
              $type = (!empty($this-&gt;hasReference('type-'.$make-&gt;type)))
                  ? $this-&gt;getReference('type-'.$make-&gt;type)
                  : false;
              if ($type) {
                  $newMake-&gt;setType($type);
              }
  
              $manager-&gt;persist($newMake);
          }
  
          $manager-&gt;flush();
      }
  }
  </code></pre>
  
  <p>I see in the console they are definitely executing in the right order. Clearly I'm setting <code>$this-&gt;make</code> and <code>$this-&gt;type</code> to <code>new ArrayCollection()</code>s in the constructors, but that was added by the entity generator and it seems like what I want.</p>
  
  <p>When I dump the <code>get_class</code> on the <code>$type</code> object in the Make fixture I see that it is a <code>Proxies\__CG__\App\Entity\Type</code> which should be right?</p>
  
  <p>Edit: My schema looks like this:</p>
  
  <pre><code>vehicle_type:
  | code        | varchar(10)  | NO   | PRI | NULL    |       |
  | description | varchar(255) | NO   |     | NULL    |       |
  
  make:
  | code        | varchar(10)  | NO   | PRI | NULL    |       |
  | type        | varchar(10)  | YES  | MUL | NULL    |       |
  | description | varchar(255) | NO   |     | NULL    |       |
  </code></pre>