Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hydrating same type (child, parent) related entity #86

Open
Vivenco opened this issue Jun 12, 2019 · 2 comments
Open

Hydrating same type (child, parent) related entity #86

Vivenco opened this issue Jun 12, 2019 · 2 comments

Comments

@Vivenco
Copy link

Vivenco commented Jun 12, 2019

Hi all,

I need help with this one.

When I have json:api response data with relationship of same type (e.g. parent or child - relationship with it-self) and their id's are the same, Hydrator is not capable creating those relationships.

Response example:

Page with id:15 has parent with id:14, but its not present in included because it already exists in data array.

  "data": [
    {
      "type": "page",
      "id": "15",
      "attributes": {
        "internal_name": "Company",
        "active": 1,
        "parent_id": 14
      },
      "relationships": {
        "parent": {
          "data": {
            "type": "page",
            "id": "14"
          }
        }
      }
    },
    {
      "type": "page",
      "id": "14",
      "attributes": {
        "internal_name": "About us",
        "parent_id": null
      },
      "relationships": {
        "parent": {
          "data": null
        }
      }
    },
    {
      "type": "page",
      "id": "13",
      "attributes": {
        "internal_name": "Information",
        "parent_id": 1
      },
      "relationships": {
        "parent": {
          "data": {
            "type": "page",
            "id": "1"
          }
        }
      }
    }
  ],
  "included": [
    {
      "type": "page",
      "id": "1",
      "attributes": {
        "internal_name": "General",
        "parent_id": null
      }
    }
  ]
}

@kocsismate
Copy link
Member

Hi @Vivenco,

This is the intended behaviour. The authors of the JSON:API standard wrote somewhere that the response is basically an identity map where none of the items (regardless if they are in the primary data or included) doesn't appear more than once.

Does this answer solve your problem?

@kocsismate
Copy link
Member

kocsismate commented Jun 24, 2019

@Vivenco I've just realized that you are talking about the Hydrator (and not about transformers)! Sorry for confusion, I'll have a look at the issue as soon as I have some spare time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants