question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Normalization group not working in nested embedded entities

See original GitHub issue

I have the following entity structure: BrandMessage has Campaign has (CampaignSettings and RunningTime). So when I call the /api/brand-messages api the entities CampaignSettings and RunningTime are nested in the third level. Also, CampaignSettings and RunningTime are embedded entities.

When I call the /api/campaigns api, everything works as expected. runningTime and settings are present:

{
  "@context": "/app_dev.php/api/contexts/Campaign",
  "@id": "/app_dev.php/api/campaigns",
  "@type": "hydra:Collection",
  "hydra:member": [
    {
      "@id": "/app_dev.php/api/campaigns/e64a026e-1b88-11e7-8825-0242ac110002",
      "@type": "Campaign",
      "app": "/app_dev.php/api/apps/e64d3274-11e7-1b88-8825-0242ac110002",
      "runningTime": {
        "daysLeftTillEnd": 99,
        "daysLeftTillStart": -74,
        "end": "2017-07-16T02:31:13+00:00",
        "isFinished": false,
        "start": "2017-01-23T08:02:29+00:00"
      },
      "settings": {
        "participationLimit": 1,
        "receiptMandatory": true,
        "requiredProductCount": 5,
        "rewardInEuroCent": 100
      },
      "title": "...",
      "description": "..."
    },
   ...
}

But when I call the /api/brand-messages api, these properties (runningTime and settings) are just null:

{
  "@context": "/app_dev.php/api/contexts/BrandMessage",
  "@id": "/app_dev.php/api/brand-messages",
  "@type": "hydra:Collection",
  "hydra:member": [
    {
      "@id": "/app_dev.php/api/brand-messages/e64d3274-1b88-11e7-8825-0242ac110002",
      "@type": "BrandMessage",
      "backgroundImage": null,
      "campaign": {
        "@id": "/app_dev.php/api/campaigns/e64a3837-1b88-11e7-8825-0242ac110002",
        "@type": "Campaign",
        "app": "/app_dev.php/api/apps/e64d3274-11e7-1b88-8825-0242ac110002",
        "runningTime": null,
        "settings": null,
        "title": "...",
        "description": "..."
      },
      "colorPair": "secondary",
      "httpCallToActionLabel": "",
      "httpLink": "",
      "important": true,
      "type": "CAMPAIGN",
      "title": "..."
    },
    ...
  ],
  ...
}

I double checked all the serialisation groups and they even work in the third nesting level for title and description. Is there a default nesting limit for nested properties or something like that? Or am I facing a bug? 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
nik-lampecommented, Apr 12, 2017

@soyuka yes, while applying this framework (which I really love btw) in my project I stumbled across multiple problems and was not aware, that they might all have the same or similar root cause. It was totally confusing for me as well. Sorry, about that 😃

1reaction
soyukacommented, Apr 12, 2017

@nik-lampe you wrote lots of different issues / comments so it’s hard to track ^^. I added a comment in your pull request, but if there are 2 different problems we need to carefully test both and fix both separately!

  1. This null issue (IMHO it’s a serialization group issue, not related to how the ResourceClassResolver works (or maybe but I’ve a lot of embedded relations and no such issue)
  2. Then there is https://github.com/api-platform/core/issues/1025. This is indeed a bug where the Parent entity is not aware of the Child metadata. Therefore, it can not serialize properties it doesn’t know of. This is harder to fix, because the metadata is the one from Parent::class though it should be Parent::class + Child::class. The good question there is “how do we find every child that extends the parent?”. An easy fix is might be to patch this class by retrieving the metadata for table inheritance.
Read more comments on GitHub >

github_iconTop Results From Across the Web

API Platform : Groups with nested entities work only when ...
It work but only when i remove @ApiResource from the nested entity and i need it to expose my CRUD services.
Read more >
Nested field type | Elasticsearch Guide [8.5] | Elastic
The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way...
Read more >
The Serialization Process - API Platform
Changing the Serialization Context on a Per-item Basis​​ The example above demonstrates how you can modify the normalization/denormalization context based on the ...
Read more >
Chapter 8. Structuring a Redux store - liveBook · Manning
This chapter covers. Structuring relational data in Redux; Learning the pros and cons of nested data versus normalized data; Using the normalizr package ......
Read more >
Use nested and repeated fields | BigQuery - Google Cloud
For example, denormalizing an orders schema without using nested and repeated fields might require you to group the data by a field like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found