Description
One of my models has a belongs-to relationship, which references a model managed by another microservice. I'm wondering how to include resource linkage data for that one? As it's a belongs-to relationship the services knows the ID. There is no need to request the other microservice and I like to avoid that one to prevent coupling.
Let me give an example to make it more clear. Lets assume I've a posts
resource, which has a author
relationship. The authors
resources referenced are hold by another service.
The resource object for a post should look like this:
{
"type": "posts",
"id": "1",
"relationships": {
"author": {
"data": {
"type": "authors",
"id": "2"
}
}
}
}
I don't want to include the authors
resource as a compound document.
I think I need to return the reference in getRelationships
method of posts's schema. But how? I've noticed that neomerx/json-api
includes a Neomerx\JsonApi\Schema\Identifier
, which should serve this use case. But it's not available in v1
used by Laravel JSON API. Is there any other trick? If possible I would like to avoid creating a model for authors as it's not owned by this microservice.