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

Nested request returns object with incorrect "self" relation #161

Open
pnw opened this issue Oct 6, 2016 · 3 comments
Open

Nested request returns object with incorrect "self" relation #161

pnw opened this issue Oct 6, 2016 · 3 comments
Assignees
Labels

Comments

@pnw
Copy link

pnw commented Oct 6, 2016

If I make a request to http://localhost:3000/api/users/1/posts, I get the following response:

{
  "links": {
    "self": "http://localhost:3000/api/users/1/posts" // correct
  },
  "data": [
    {
      "type": "user", // this should be "post"
      "relationships": {
        "user": {
          "links": {
            "related": "http://localhost:3000/api/posts/99/user"  // correct
          }
        }
      },
      "id": "99",
      "attributes": {
        "some": "attributes"
      },
      "links": {
        "self": "http://localhost:3000/api/users/99"  // this should be "http://localhost:3000/api/posts/99"
      }
    }
  ]
}

Note the error in the URL: "http://localhost:3000/api/users/99"

The id segment is correct (this is the self link for post 99), but the model-name segment refers to the parent resource, "users", instead of the child resource, "posts"

@csprocket777
Copy link

I'm confused by this. It's the self link in the "user" entry.

@markstuart
Copy link
Collaborator

I think that part of the issue is that the type key in this example is also incorrect @csprocket777. A request to http://localhost:3000/api/users/1/posts should only return data with "type": "post". That is probably the reason why the self link is getting generated incorrectly, it is probably getting built from pluralising the type.

@digitalsadhu
Copy link
Owner

yeah as @markstuart says its not just the "self" but also the "type" that's wrong. I've updated the issue text to highlight this

@Tronix117 Tronix117 self-assigned this Dec 28, 2017
@Tronix117 Tronix117 added the bug label Dec 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants