12

self以下の JSONAPI リソースでとrelatedの参照が異なるのはなぜですか? それらは同じリソースを指していませんか? /articles/1/relationships/tags行くと行く はどう違い/articles/1/tagsますか?

{
  "links": {
    "self": "/articles/1/relationships/tags",
    "related": "/articles/1/tags"
  },
  "data": [
    { "type": "tags", "id": "2" },
    { "type": "tags", "id": "3" }
  ]
}
4

2 に答える 2

3

それらは違う。これが私のプロジェクトの例です。

試してGet http://localhost:3000/phone-numbers/1/relationships/contactみると、次のような応答が得られます。

{
  "links": {
    "self": "http://localhost:3000/phone-numbers/1/relationships/contact",
    "related": "http://localhost:3000/phone-numbers/1/contact"
  },
  "data": {
    "type": "contacts",
    "id": "1"
  }
}

おそらく取得したい と を取得できませんでした。attributesrelationships

次に、試してGet http://localhost:3000/phone-numbers/1/contactみると、次のような応答が得られます。

{
  "data": {
    "id": "1",
    "type": "contacts",
    "links": {
      "self": "http://localhost:3000/contacts/1"
    },
    "attributes": {
      "name-first": "John",
      "name-last": "Doe",
      "email": "john.doe@boring.test",
      "twitter": null
    },
    "relationships": {
      "phone-numbers": {
        "links": {
          "self": "http://localhost:3000/contacts/1/relationships/phone-numbers",
          "related": "http://localhost:3000/contacts/1/phone-numbers"
        }
      }
    }
  }
}

attributesとを含む、必要なすべての情報を取得したことがわかりますrelationships

relationshipsしかし、それは何らかの目的に使用できることを知っておく必要があります。サンプルとしてhttp://jsonapi.org/format/#crud-updating-to-one-relationshipsをお読みください。

于 2017-04-20T10:06:43.097 に答える