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

Relationship validation issue #6

Open
X-Coder264 opened this issue Sep 27, 2021 · 0 comments
Open

Relationship validation issue #6

X-Coder264 opened this issue Sep 27, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@X-Coder264
Copy link

Due to https://github.com/undabot/json-api-symfony/blob/v2.2.2/src/Service/Resource/Validation/ResourceValidator.php#L91 I have to send all defined relationships when creating a resource.

Let's say for example that I have user and posts resources and a one to many relationship is defined between user and posts. Sending this payload (which is perfectly valid according to the spec) results in a validation error (which shouldn't happen).

{
  "data": {
    "type": "users",
    "attributes": {
      "foo": "bar"
    }
  }
}
{
  "errors": [
    {
      "title": "This field is missing.",
      "source": {
        "pointer": "/data/relationships/posts"
      }
    }
  ]
}

So I have to send this instead:

{
  "data": {
    "type": "users",
    "attributes": {
      "foo": "bar"
    },
    "relationships": {
      "posts": {
        "data": []
      }
    }
  }
}
@penovic penovic self-assigned this Sep 27, 2021
@penovic penovic added the bug Something isn't working label Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants