-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Is your feature request related to a problem? Please describe.
Nope, just preparing for some optimizations
Describe the solution you'd like
I have some attributes that I send with every model, that I don't really need to, so I plan on moving them into the meta object.
For example, createdAt and updatedAt will be on the resource's meta object. These fields are read-only from the client perspective, as they are handled entirely by the server. This I could keep in the attributes, so this Feature Request isn't a hard requirement. That said, where I do need it, is for relationship counts. Basically, consider querying notification count. I can configure my jsonapi server to send this via the related link's meta object.
Describe alternatives you've considered
I can keep the createdAt and updatedAt in the attributes without issue. As for querying notificationCount, I'd probably need to use json-rpc to query those values. Not impossible, but inconvinient.
Additional context
The best solution, which may not be possible as there isn't a standard of how count is added to meta (or meta objects really), would be for this library to read the link related meta object's count field and create a PaginateEntityCollection for that relationship with the provided count as the totalCount. We don't need any data at this point, but can easily fetch said data.
As always, I am willing to help
Here is an example payload with count, that said, since count isn't really a standard, developers might have it as a different name. Most instances won't even have it.
{
"data": {
"type": "posts",
"id": "1",
"attributes": {
"content": "...",
"title": "Hello World"
},
"relationships": {
"comments": {
"links": {
"self": "http://localhost/api/v1/posts/1/relationships/comments",
"related": "http://localhost/api/v1/posts/1/comments"
},
"meta": {
"count": 17
}
},
"tags": {
"links": {
"self": "http://localhost/api/v1/posts/1/relationships/tags",
"related": "http://localhost/api/v1/posts/1/tags"
},
"meta": {
"count": 4
}
}
},
"links": {
"self": "http://localhost/api/v1/posts/1"
}
}
}