Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Non-existent one-to-one relationships #94

@johnmaguire

Description

@johnmaguire

Hi there,

I'm taking a look at this part of the spec on relationships.

Resource linkage MUST be represented as one of the following:

  • null for empty to-one relationships.
  • an empty array ([]) for empty to-many relationships.
  • a single resource identifier object for non-empty to-one relationships.
  • an array of resource identifier objects for non-empty to-many relationships.

I'm not sure if my understanding is incorrect or not. My URL looks like this: GET /v1/devices?include=group

I have done this to get the "relationships" key to show up for all items:

    public function group($device)
    {
        return new Relationship(
            $device['group_id'] ? new Resource([
                'id' => $device['group_id'],
                'name' => $device['group_name'],
            ], new GroupSerializer) : null
        );
    }

Originally I tried to return null instead of a Relationship, but that removes the "relationships" block entirely. The only problem with the above solution is that it seems to only support "X-to-many" relationships. In other words, the response from the API looks like this:

"relationships": {
    "group": []
}

I believe that in reality, I want it to look like this:

"relationships": {
    "group": null
}

Is there any way to get this result? Thank you so much for this library! It's very flexible and useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions