title: How to display nested documents in API Platform
body: <p>I'm trying to display nested documents as a default, meaning when I query the api, it should return the documents with their relationships.</p>
  
  <p>Two of my entities:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use ApiPlatform\Core\Annotation\ApiResource;
  use App\Traits\TimestampableTrait;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ApiResource()
   * @ORM\Entity(repositoryClass="App\Repository\ClaimRepository")
   * @ORM\Table("claims")
   */
  class Claim
  {
      use TimestampableTrait;
  
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $name;
  
      /**
       * @ORM\OneToMany(targetEntity="App\Entity\Activity", mappedBy="claim", cascade={"persist", "remove"})
       */
      private $activities;
  
      /**
       * @ORM\ManyToMany(targetEntity="App\Entity\ClaimState", inversedBy="claims", cascade={"persist", "remove"})
       * @ORM\OrderBy({"id" = "desc"})
       */
      private $states;
  </code></pre>
  
  <p>And the other one:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use ApiPlatform\Core\Annotation\ApiResource;
  use App\Traits\TimestampableTrait;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ApiResource()
   * @ORM\Entity(repositoryClass="App\Repository\ActivityRepository")
   * @ORM\Table("activities")
   */
  class Activity
  {
      use TimestampableTrait;
  
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $name;
  
      /**
       * @ORM\ManyToOne(targetEntity="App\Entity\Claim", inversedBy="activities")
       */
      private $claim;
  
      /**
       * @ORM\OneToMany(targetEntity="App\Entity\Invoice", mappedBy="activity", orphanRemoval=true, cascade={"persist","remove"})
       */
      private $invoices;
  
      /**
       * @ORM\OneToMany(targetEntity="App\Entity\ActivityError", mappedBy="activity", cascade={"persist","remove"})
       */
      private $errors;
  </code></pre>
  
  <p>When I do <code>GET /claims</code> I would like it to display the <code>Activity</code> relations with all the properties, what I get right now is:</p>
  
  <pre><code>{
    "data": {
      "id": "/claims/7",
      "type": "Claim",
      "attributes": {
        "_id": 7,
        "name": "My Valid Claim",
        "created": "2019-01-07T15:14:21+01:00",
        "updated": "2019-01-07T15:14:21+01:00"
      },
      "relationships": {
        "activities": {
          "data": [
            {
              "type": "Activity",
              "id": "/activities/7"
            }
          ]
        }
      }
    }
  }
  </code></pre>
  
  <p>I would like to get something like this:</p>
  
  <pre><code>{
    "data": {
      "id": "/claims/7",
      "type": "Claim",
      "attributes": {
        "_id": 7,
        "name": "My Valid Claim",
        "created": "2019-01-07T15:14:21+01:00",
        "updated": "2019-01-07T15:14:21+01:00"
      },
      "relationships": {
        "activities": {
          "data": [
            {
              "type": "Activity",
              "id": "/activities/7",
              "attributes": {
                "_id": 7,
                "name": "Activity no. 1",
                "created": "2019-01-07T15:14:21+01:00",
                "updated": "2019-01-07T15:14:21+01:00"
              },
              "relationships": {
                "invoices": {
                  "data": [
                    {
                      "type": "Invoice",
                      "id": "/invoices/7",
                      "attributes": {
                        "_id": 7,
                        "vendor": "Vendor Ltd."
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    }
  }
  </code></pre>
  
  <p>The format used is <code>JSON:API</code>. I tried using groups, but it doesn't help at all and I can't find anything in any documentation.</p>
  
  <p>Any help is appreciated.</p>