title: Symfony 5 API populate related object entities
body: <p>I am trying to create a simple web app using Symfony 5. I am using the <a href="https://api-platform.com/" rel="nofollow noreferrer">API</a>.</p>
  <p>Currently when calling some endpoint it only displays the IRI link to the related link:</p>
  <p><img src="https://i.imgur.com/um7ZkWG.png" alt="" /></p>
  <p>I need instead to display the related entity object itself; if I get the <code>Item</code> endpoint the related entity <code>Program</code> should be returned this:</p>
  <pre><code>{
      &quot;id&quot;: 1,
      &quot;program&quot;: {
          &quot;id&quot;: 1,
          &quot;name&quot;: &quot;First program&quot;
      },
      &quot;description&quot;: &quot;fgdfg&quot;,
      &quot;comment&quot;: &quot;dfgdfg&quot;
  {
  </code></pre>
  <p>So, this is how the table looks:</p>
  <p><img src="https://i.imgur.com/rTGuBXY.png" alt="" /></p>
  <p>I thought <a href="https://api-platform.com/docs/core/subresources/" rel="nofollow noreferrer">setting up a subresource</a> would be enough to get the object but it wasn't:</p>
  <ol>
  <li><p>In the <code>InventoryItem</code> entity configured <code>@ApiSubresource</code> annotation of the <code>Program</code> property:</p>
  <pre><code>/**
   * @ORM\ManyToOne(targetEntity=Program::class, inversedBy=&quot;inventoryItems&quot;)
   * @ORM\JoinColumn(nullable=false)
   * @ApiSubresource
   */
  private $program;
  </code></pre>
  </li>
  <li><p>In <code>resources.yaml</code> file I configured the subresource:</p>
  <pre class="lang-yaml prettyprint-override"><code>App\Entity\InventoryItem:
     properties:
         program:
             subresource:
                 resourceClass: 'App\Entity\Program'
                 collection: true
  </code></pre>
  </li>
  </ol>
  <p>This still returns the IRI instead of the object, The only thing that has changed was that now I can access to the related entity for the current object in this URL: <code>http://localhost:8000/api/inventory_items/1/program.json</code>.</p>
  <p>Any idea on how to return the related entity object itself instead of the IRI URL?</p>