json-api icon indicating copy to clipboard operation
json-api copied to clipboard

[Issue-69] Adjust relation call for nulled resources

Open cube-dainis opened this issue 10 months ago • 0 comments

When requesting a nested include such as destination.location for a stop resource, if the stop does not have a destination attached, the request currently fails with an error. This behavior is inconsistent with the JSON:API specification, which requires that missing nullable relationships should return null.

Solution:

Adjusted the resolveRelationships method in the Relationships trait to handle cases where a requested relationship is missing.

Example Behavior After Fix:

Requesting destination.location for a stop without a destination will return:

"relationships": {
    "destination": {
        "data": null
    }
}

Linked Issue: https://github.com/timacdonald/json-api/issues/69

cube-dainis avatar Jan 13 '25 14:01 cube-dainis