Skip to content

Recommendation for empty to-one relationship related link #1134

Closed

Description

@beauby

Suppose a post has one author, that can be nil. When fetching /posts/3, without ?include=author, should the related link:

  1. not be present at all? (and only the self link be present)
  2. point to /posts/3/author, which responds with a 404?

Activity

  1. rpkilby commented on Dec 21, 2016

    @rpkilby

    We've preferred the second option, because you can still use that link to create the related resource and relationship linkage.

  2. beauby commented on Dec 22, 2016

    @beauby
    ContributorAuthor

    @rpkilby My understanding is that what you're describing is actually the role of the relationship endpoint (i.e. the value of the self link, rather than the related one, which as I understand it, is supposed to point to the resource itself).

  3. rpkilby commented on Dec 22, 2016

    @rpkilby

    Sorry - wasn't entirely clear. The related resource link is useful because it allows you to use one request to both create a resource and then implicitly link it to the parent object. eg, you could POST /api/posts/3/author, which would create a new author resource and set it to the post's author relationship. Without the related link, you would need to use two requests.

    POST /api/authors
    PUT /api/posts/3/relationships/author

    #496 and #962 might be helpful.

  4. beauby commented on Dec 22, 2016

    @beauby
    ContributorAuthor

    @rpkilby Thanks for the clarification, that makes sense. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions