title: Doctrine Fixtures doesn't get persisted, why?
body: <p>I have a small set of Doctrine DataFixtures which is setup as follow:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ tree -A code/src/AppBundle/DataFixtures/ORM/
  code/src/AppBundle/DataFixtures/ORM/
  ├── LoadCategoryData.php
  ├── LoadCategoryHasPostData.php
  └── LoadPostData.php
  </code></pre>
  
  <p>See the following output when I try to load the fixtures:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ docker exec -u www-data -it coding_webserver_1 php bin/console doctrine:fixtures:load -vvv
  Careful, database will be purged. Do you want to continue y/N ?y
    &gt; purging database
    &gt; loading [1] AppBundle\DataFixtures\ORM\LoadCategoryData
    &gt; loading [2] AppBundle\DataFixtures\ORM\LoadPostData
    &gt; loading [3] AppBundle\DataFixtures\ORM\LoadCategoryHasPostData
  
  
    [Symfony\Component\Debug\Exception\FatalThrowableError]                                                                                                                                                         
    Type error: Argument 1 passed to AppBundle\Entity\CategoryHasPosts::setCategory() must be an instance of AppBundle\Entity\Category, null given, called in /var/www/src/AppBundle/DataFixtures/ORM/LoadCategory  
    HasPostData.php on line 22
  </code></pre>
  
  <p>This is how the file <code>LoadCategoryData</code> looks like:</p>
  
  <pre class="lang-php prettyprint-override"><code>class LoadCategoryData extends AbstractFixture implements OrderedFixtureInterface
  {
      public function load(ObjectManager $manager)
      {
          $category_1 = new Category();
          $category_1-&gt;setCategoryName('Hot');
          $category_1-&gt;setCategoryDescription('Hot Topics');
          $category_1-&gt;setSlug('hot');
          $category_1-&gt;setActive(true);
          $manager-&gt;persist($category_1);
  
          $category_2 = new Category();
          $category_2-&gt;setCategoryName('New');
          $category_2-&gt;setCategoryDescription('New Topics');
          $category_2-&gt;setSlug('new');
          $category_2-&gt;setActive(true);
          $manager-&gt;persist($category_2);
  
          $manager-&gt;flush();
      }
  
      public function getOrder()
      {
          return 1;
      }
  }
  </code></pre>
  
  <p>This is the content of <code>LoadPostData</code> file:</p>
  
  <pre class="lang-php prettyprint-override"><code>class LoadPostData extends AbstractFixture implements OrderedFixtureInterface
  {
      public function load(ObjectManager $manager)
      {
          $faker = Faker\Factory::create();
  
          for ($i = 0; $i &lt; 1000; $i++) {
              $post = new Post();
              $post-&gt;setPostTitle($faker-&gt;sentence);
              $post-&gt;setPostContent($faker-&gt;paragraph);
              $post-&gt;setSlug($faker-&gt;slug);
  
              $manager-&gt;persist($post);
          }
  
          $manager-&gt;flush();
      }
  
      public function getOrder()
      {
          return 2;
      }
  }
  </code></pre>
  
  <p>And this is the content of <code>LoadCategoryHasPostData</code> file:</p>
  
  <pre class="lang-php prettyprint-override"><code>class LoadCategoryHasPostData extends AbstractFixture implements OrderedFixtureInterface
  {
      public function load(ObjectManager $manager)
      {
          for ($i = 0; $i &lt; 2000; $i++) {
              $category_id = random_int(1, 2);
              $category    = $manager-&gt;getRepository('AppBundle:Category')-&gt;find($category_id);
  
              $post_id = random_int(1, 2000);
              $post    = $manager-&gt;getRepository('AppBundle:Post')-&gt;find($post_id);
  
              $categoryHasPost = new CategoryHasPosts();
              $categoryHasPost-&gt;setCategory($category);
              $categoryHasPost-&gt;setPost($post);
  
              $manager-&gt;persist($categoryHasPost);
          }
  
          $manager-&gt;flush();
      }
  
      public function getOrder()
      {
          return 3;
      }
  }
  </code></pre>
  
  <p>I know why the process is failing and it's logic: the previous entities weren't persisted and this is my why goes to. </p>
  
  <p>Why <code>Category</code> and <code>Post</code> weren't persisted and flushed? What I am missing here?</p>