Skip to content

Relationship without data property #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OndraM opened this issue Feb 19, 2019 · 3 comments
Closed

Relationship without data property #92

OndraM opened this issue Feb 19, 2019 · 3 comments
Labels

Comments

@OndraM
Copy link
Contributor

OndraM commented Feb 19, 2019

Hi,
I'd like to create resource with following relationship my_relation, which only contains links property, ie. there is no data property with resource linkage:

{
    "data": {
        "type": "...",
        "id": "...",
        "relationships": {
            "my_relation": {
                "links": {
                    "related": "/foo"
                }
            }
        }
    }
}

This is allowed as per JSON:API spec:

A “relationship object” MUST contain at least one of the following:
- links: a links object
- data: resource linkage
- meta: a meta object that contains non-standard meta-information about the relationship.

Is there any way how to accomplish this now, with version 2 of the library? It was possible with version 1:

$resourceObject->setRelationship('my_relation', Relationship::fromRelatedLink('/foo'));

However now there seems to be only ToNull, ToOne and ToMany relation, neither of which accomplishes exactly this (eg. ToNull adds data: null to the relationship).

@f3ath f3ath added the bug label Feb 19, 2019
@f3ath
Copy link
Contributor

f3ath commented Feb 19, 2019

Yep, you're right. The "at least one" clause makes data optional. Seems like introducing some sort of an EmptyRelationship implements ResourceField might solve this. What do you think?

@OndraM
Copy link
Contributor Author

OndraM commented Feb 20, 2019

👍 Yes, this is basically what I did as workaround. Though I'm not sure about EmptyRelationship name - it suggest the relationship is empty, but it just does not contain the linkage identifier (ResourceIdentifier). However I can't think of better suggestion :)

@f3ath
Copy link
Contributor

f3ath commented Feb 20, 2019

Feel free to submit a PR if you have it already.

f3ath added a commit to f3ath/json-api-php that referenced this issue Feb 23, 2019
@f3ath f3ath closed this as completed in 5f47c15 Feb 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants