# Relationships level or basic rules joining related resourses

**URL:** <https://discuss.jsonapi.org/t/relationships-level-or-basic-rules-joining-related-resourses/293>\
**Category:** Uncategorized\
**Created:** [January 6, 2016, 9:25pm UTC](https://discuss.jsonapi.org/t/relationships-level-or-basic-rules-joining-related-resourses/293 "2016-01-06T21:25:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![deividas](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@deividas](https://discuss.jsonapi.org/u/deividas)\
**Post date:** [January 6, 2016, 9:25pm UTC](https://discuss.jsonapi.org/t/relationships-level-or-basic-rules-joining-related-resourses/293/1 "2016-01-06T21:25:28Z")

</div>

Hello,

I have tried to google and search in this disccuss board but with no luck. It’s possible that following question is too abstract and arose because i missed something in [jsonapi.org](http://jsonapi.org) specification or here in search results.

The question is about how to handle resourses which are related to each other and also how i should ( by convention ) access these resourses and when i should use relationship between them and when i should access them as seperate resourses.

There’s concrete example. Let’s assume that we have resourses that are related to each other: Countries, States and Cities. So, countries has many states, states has many cities and i’m going implement something like this: [http://www.91weblessons.com/demo/codeigniterCountryStateCityDropDown/index.php](http://www.91weblessons.com/demo/codeigniterCountryStateCityDropDown/index.php)

The first idea is to have three seperate endpoints:

- /v1/module/countries
- /v1/module/states
- /v1/module/cities

There’s a workflow:

Retrieved all countries from countries endpoint and have chosen “Vietnam”.  
Now i need to retrieve all Vietnam states.  
When i got all states in some way i have chosen An Giang state and now i need to get all cities for this state.

Should i use here relationship or not and in case i should how it should look like?

There’s some mine thoughts:

- /v1/counties/country:id/relationship/states -
- /v1/states/states:id/relationship/cities

Or should i use just links to original resourses:

- /v1/states?filter[country:id]=country:id
- /v1/cities?filter[state:id]=state:id

If i do understand correctly all these relationships are just links to original resourse just represended in relationship manner. /v1/counties/country:id/relationship/states actualy is link to /v1/states?filter[country:id]=country:id ?

Also i would appreaciate any guidliness related API development.

---

<div class="post-metadata">

**Author:** ![deividas](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@deividas](https://discuss.jsonapi.org/u/deividas)\
**Post date:** [January 7, 2016, 8:53am UTC](https://discuss.jsonapi.org/t/relationships-level-or-basic-rules-joining-related-resourses/293/2 "2016-01-07T08:53:51Z")

</div>

I have done some research:

> [@Usage of \`related\` field in Relationships link](https://discuss.jsonapi.org/t/usage-of-related-field-in-relationships-link/145/8):
>
> > [@Usage of \`related\` field in Relationships link](https://discuss.jsonapi.org/t/usage-of-related-field-in-relationships-link/145/7):
> >
> > And if musicians also had another association, like, their “preferred” equipment, could those relationships be included as part of the document above, say under data.relationships?
> 
> Definitely. The drummer represented is just a standard resource object, so it can certainly include relationships of its own. In fact, it should include those additional relationships if they exist (unless there’s a ?fields restriction). That way, users can just follow one relationship to the next, to the next, without ever having to go back and request /musicians/9 directly.

From here: [Usage of `related` field in Relationships link - #8 by ethanresnick](http://discuss.jsonapi.org/t/usage-of-related-field-in-relationships-link/145/8)

So, in real word example ( from my previous post ) i believe it should like something like this:

```
GET /v1/module/countries

{
  "links": {
    "self": "https://example.com/v1/module/countries"
  },
  "data": {
    "id": "county_id",
    "type": "countries",
    "relationships": {
      "state": {
        "links": {
          "related": "https://example.com/countries/county_id/states" // states is plural, it's ok?
        },
        "data": {"id": "state_id", "type": "state"}
      }
    }
  },

  "included": [{
    "id": "state_id",
"type": "state",
"attributes": {

},
"relationships": {
  "cities": {
    "links": {
      "related": "https://example.com/state/state_id/cities" // cities is plural, it's ok?
    },
    "data": {
      "id": "cities", // what about cities id
      "type": "accountProfile"
    }
  }
}]
  }
 }

```

According this resource: [Is it ok to add multiple levels of nested relationships in the relationships field - #2 by ethanresnick](http://discuss.jsonapi.org/t/is-it-ok-to-add-multiple-levels-of-nested-relationships-in-the-relationships-field/167/2)

But still i feel like missing something and confused about all these relationships and i don’t see any logical reasoning and connections between this complexity.
