kamikat / moshi-jsonapi

JSON API v1.0 Specification in Moshi.
MIT License
156 stars 34 forks source link

Get inluded data #65

Closed ernestalmighty closed 7 years ago

ernestalmighty commented 7 years ago

Since version 3.0, Document.included is not accessible. How to get all included data without knowing the id?

kamikat commented 7 years ago

Is there any example of the use case?

ernestalmighty commented 7 years ago
{
  "data": {
    "type": "accounts",
    "id": "2593177",
    "attributes": {
      "payment-type": "prepaid",
      "unbilled-charges": null,
      "next-billing-date": null,
      "title": "Ms",
      "first-name": "Joe",
      "last-name": "Bloggs",
      "date-of-birth": "1985-01-01",
      "contact-number": "0404000000",
      "email-address": "test@amaysim.com",
      "email-address-verified": false,
      "email-subscription-status": false
    },
    "links": {
      "self": "http://localhost:3000/accounts/2593177"
    },
    "relationships": {
      "services": {
        "links": {
          "related": "http://localhost:3000/services/0468874507"
        }
      }
    }
  },
  "included": [
    {
      "type": "services",
      "id": "0468874507",
      "attributes": {
        "msn": "0468874507",
        "credit": 1200,
        "credit-expiry": "2016-11-20",
        "data-usage-threshold": false
      },
      "links": {
        "self": "http://localhost:3000/services/0468874507"
      },
      "relationships": {
        "subscriptions": {
          "links": {
            "related": "http://localhost:3000/services/0468874507/subscriptions"
          },
          "data": [
            {
              "type": "subscriptions",
              "id": "0468874507-0"
            }
          ]
        }
      }
    },
    {
      "type": "subscriptions",
      "id": "0468874507-0",
      "attributes": {
        "included-data-balance": 52400,
        "included-credit-balance": null,
        "included-rollover-credit-balance": null,
        "included-rollover-data-balance": null,
        "included-international-talk-balance": null,
        "expiry-date": "2016-11-19",
        "auto-renewal": true,
        "primary-subscription": true
      },
      "links": {
        "self": "http://localhost:3000/services/0468874507/subscriptions/0468874507-0"
      },
      "relationships": {
        "service": {
          "links": {
            "related": "http://localhost:3000/services/0468874507"
          }
        },
        "product": {
          "data": {
            "type": "products",
            "id": "0"
          }
        },
        "downgrade": {
          "data": null
        }
      }
    },
    {
      "type": "products",
      "id": "4000",
      "attributes": {
        "name": "UNLIMITED 7GB",
        "included-data": null,
        "included-credit": null,
        "included-international-talk": null,
        "unlimited-text": true,
        "unlimited-talk": true,
        "unlimited-international-text": false,
        "unlimited-international-talk": false,
        "price": 3990
      }
    }
  ]
}

In this example data, for example I'd like to get the included values for the products type

kamikat commented 7 years ago

The accounts entity in example data has a relationship named services with only links. Therefore, the included resources should not appear here but on request of http://localhost:3000/services/0468874507/subscriptions.