danivek / json-api-serializer

Node.js/browser framework agnostic JSON API (http://jsonapi.org/) serializer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow relationships to have an alternative key if relationship key not exist

danivek opened this issue · comments

Some ORM (like js-data) have two keys in object for defining a relation :

  • a key with id or ids (unpopulated relation)
  • a key with a populated relation

example for an article with a relation with a user :

{
  "id": "1",
  "title": "Nice article",
  "user_id": "2", // unpopulated user
  "user": { // populated user
    "id": "2",
    "name": "John Doe"
  }
}

If we not explicitly populate relation in the ORM, we only have the user_id key in object.

So, relationships configuration could have an alternative key to watch for unpopulated relationships if the populate relationship key does not exist.