title: symfony4 How create DataFixtures with entities relations
body: <p>Under Symfony4.2, I have a <em>Translate</em> entity (id, gb_name, fr_name) and <em>LocationCountry</em> entity (id, ISO3166-2 name: GB,FR, DE…, translate_id)</p>
  
  <p>I define a CSV file with 255 countries ("GB", "Great Britain", "Angleterre"…) and I want to push it in Translate and LocationCountry entities tables with DataFixture.</p>
  
  <p>I read carefully  <a href="https://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html#sharing-objects-between-fixtures" rel="nofollow noreferrer">https://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html#sharing-objects-between-fixtures</a><br>
  and<br>
  <a href="https://stackoverflow.com/questions/38122653/php-create-fixtures-with-automatic-relations">php create fixtures with automatic relations</a></p>
  
  <p>src/DataFixtures/TranslateFixtures.php:</p>
  
  <pre><code>if ($csv_handle) {
          while ($item = fgetcsv($csv_handle, $csv_max_line_length, $csv_delimiter, $csv_enclosure)) {
              $obj = new Translate();
              $obj-&gt;setGbValue($item[1]);
              $obj-&gt;setFrValue($item[2]);
              $this-&gt;addReference('country'.$item[0], $obj);
              $manager-&gt;persist($obj);
          }
          fclose($csv_handle);
      }
  
      $manager-&gt;flush();
  </code></pre>
  
  <p>I am not sure <em>addReference</em> should be before <em>flush()</em>  ?</p>
  
  <p>src/DataFixtures/LocationCountryFixtures.php:</p>
  
  <pre><code>    if ($csv_handle) {
          while ($item = fgetcsv($csv_handle, $csv_max_line_length, $csv_delimiter, $csv_enclosure)) {
              $translate_country = $this-&gt;getReference('country'.$item[0]);
              $obj = new LocationCountry();
              $obj-&gt;setIso3166Name($item[0]);
              $obj-&gt;setTranslate($translate_country);
              $manager-&gt;persist($obj);
          }
          fclose($csv_handle);
      }
  
      $manager-&gt;flush();
  }
  
  public function getDependencies() {
      return array(
          Translate::class,
      );
  }
  </code></pre>
  
  <p>If I remove <em>addReference</em> Translate entity is well filled.</p>
  
  <p>But with the code above, it returns error:  </p>
  
  <pre><code>In SymfonyFixturesLoader.php line 76:                                                                                                                                             
  The "App\Entity\Translate" fixture class is trying to be loaded, but is not available. Make sure this class is defined as a service and tagged with "doctrine.fixture.orm". 
  </code></pre>
  
  <p>I think to have the right Use:</p>
  
  <pre><code>use Doctrine\Bundle\FixturesBundle\Fixture;
  use Doctrine\Common\Persistence\ObjectManager;
  use Doctrine\Common\DataFixtures\DependentFixtureInterface;
  use App\Entity\LocationCountry;
  use App\Entity\Translate;
  </code></pre>
  
  <p>Thank for your help</p>