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

Missing data in response if using omitDataWhenNotIncluded #103

Closed
Art4 opened this issue Feb 23, 2021 · 7 comments
Closed

Missing data in response if using omitDataWhenNotIncluded #103

Art4 opened this issue Feb 23, 2021 · 7 comments

Comments

@Art4
Copy link
Contributor

Art4 commented Feb 23, 2021

I have found a potential bug with omitDataWhenNotIncluded and relationships.

In the examples there is a UserResource, see https://github.com/woohoolabs/yin/blob/4.2.1/examples/User/JsonApi/Resource/UserResource.php#L120

The user resource has a contacts relationship that data is set with setDataAsCallable() and omitDataWhenNotIncluded().

If I call the example url /users/1/relationships/contacts I get a response without any data. Only the links are there:

{
  "links": {
    "self": "\/users\/1\/contacts",
    "related": "\/users\/1\/relationships\/contacts"
  }
}

If i remove the call of ->omitDataWhenNotIncluded() I get the correct response:

{
  "links": {
    "self": "\/users\/1\/contacts",
    "related": "\/users\/1\/relationships\/contacts"
  },
  "data": [
    {
      "type": "contacts",
      "id": "100"
    },
    {
      "type": "contacts",
      "id": "101"
    },
    {
      "type": "contacts",
      "id": "102"
    }
  ]
}

I think omitDataWhenNotIncluded should be ignored if we want to respond with the relationship.

@kocsismate
Copy link
Member

Hi @Art4

Hmm, yes, it seems like an issue indeed, thanks for bringing it up! Are you up for providing a PR or would you prefer if I did so?

@Art4
Copy link
Contributor Author

Art4 commented Mar 30, 2021

I tried to create a PR but I struggled at finding a solution. If you know how this can be fixed I would prefer you create a PR.

@kocsismate
Copy link
Member

I think I know what should be changed. :) I'll have a look.

@kocsismate
Copy link
Member

I've added 6a4284b - please test if it works for you (p.s. I accidentally added the release date, it's not yet done)

@Art4
Copy link
Contributor Author

Art4 commented Apr 14, 2021

Thank you very much. I hope I will get the time to test it this weekend.

@kocsismate
Copy link
Member

I've released 4.3.0 in the meanwhile, but please come back to me should you find any issues with the implementation.

@Art4
Copy link
Contributor Author

Art4 commented Apr 24, 2021

I've tested this issue with 4.3.0 and can confirm that this bug is fixed. Thank you very much. 👍

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