Relationships data object - id is not primary key - ability to rename id key

Sorry if this is not the right place for this kind of problem or if someone else already faced with the same problem.
Fell free to redirect me or whatever.

So I just faced a problem when I do not use id as a primary key. I would need something like this (see relationships dispatchers data part):

{
  "data": {
    "type": "driver",
    "attributes": {
      "first_name": "First name",
      "last_name": "last name",
    },
    "relationships": {
      "dispatchers": {
        "data": [
          {
            "type": "dispatcher",
            "tspa_id": "8"
          },
          {
            "type": "dispatcher",
            "tspa_id": "7"
          }
        ]
      }
    }
  },
  "included": [
    {
      "id": "",
      "type": "dispatcher",
      "attributes": {
        "first_name": "Maybelle",
        "last_name": "Merlin",
        "tspa_id": "7" 
      }
    }
  ]
}

So I am not sure if my suggestion is good, but I think that json api specification should allow us to:

  • rename primary key

  • use another key as primary key

Any other opinions or solutions?

Thanks!

You are confusing your JSON:API schema and you database schema. The JSON:API specification never mentions the terms “primary key”.

Can you tell us a little more about what you are trying to achieve? Why can’t the driver have an ID? Why can’t a dispatcher use the name ID?

Sorry for late reply. In fact I differentiate json api schema vs database schema. Currently to achieve the wanted behaviour I have to map one schema to other one. In case that json api schema has possibility to use other name for id key, then I do not need mapping.

The background problem is that I have two systems that have to be synched, first system is older then 5 years, and the other one is new one. Both system uses postgres as a database, and because of above we have different ids for same resource. So we are not able to match object based on id, and we have introduced tspa_id to be same on both systems. And now we are facing with matching problems (in included part of the json api schema). As a quick solution we added attribute instead relationships that has list of dispatcher ids.

Just as note: I do not claim that my proposed solution is correct, good or whatever. Let’s say I have edge case, and I just wanted to bring it to light, so that people that made json api schema, have additional information about other use cases and possible solutions.