Skip to content

Parent reference in related links #405

@ssbb

Description

@ssbb

Hi! I am quite new to jsonapi so forgive me if I got something wrong (or asking for something wrong) but looking at the spec examples I see this:

{
  "data": [{
      "type": "comments",
      "id": "1",
      "attributes": {
          "text": "HATEOS are the thing!"
      },
      "links": {
          "self": "/comments/1"
      },
      "relationships": {
        "author": {
          "links": {
            "self": "/comments/1/relationships/author",
            "related": "/comments/1/author"
          }
        },
        "articles": {
          "links": {
            "self": "/comments/1/relationships/articles",
            "related": "/comments/1/articles"
          }
        }
      }
  }],
  "links": {
      "self": "/comments"
  }
}

Few things I noticed when tried to implement similar relationships:

  1. related link generator unaware of the parent so this lib would generate just /articles instead of /comments/1/articles. url_for on the child view gets just the collection and the conn. But anyway I think it makes more sense to do it on the parent view level similar to url_for_rel but for related links.
  2. There currently no way to generate links without preloading whole association? Looking at the code it seems to skip whole thing if association not preloaded. With this spec example in mind - wouldn't it make more sense to just omit data section then but still generate the links?

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