Api Platform 3: APIs RESTful míticamente buenas
Relaciones incrustadas
  Start your All-Access Pass to unlock this challenge
Buy Access Login

Challenge 1 / 1

Suppose we have a Product entity with the following category property:

#[ApiResource(normalizationContext: ['groups' => 'product:read']]
class Product
{
    // ...
    #[Groups('product:read')]
    public Category $category;
}

And Category looks like this:

#[ApiResource(normalizationContext: ['groups' => 'category:read']]
class Category
{
    // ...
    #[Groups('category:read')]
    public string $name;
}

Right now, when you make a GET request to /api/products/3, the response looks like this:

{
    "@id": "/api/products/3",
    "@type": "Product",
    "category": "/api/categories/5"
}

Instead of the IRI, what is the easiest way to turn the category field into an object with the category's name inside?

Skip challenges and go to theNext Chapter

Turn Challenges Off?

All further challenges will be skipped automatically.
You can re-enable challenges at any time on this page or from your account page.