Skip to content

Add ability to define relationships in Schema differently when resource is main and included #121

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
neomerx opened this issue Mar 24, 2016 · 1 comment
Assignees
Milestone

Comments

@neomerx
Copy link
Owner

neomerx commented Mar 24, 2016

Relationship could be represented by all resource identities (type and id) in the relationship, or a link, or a combination of data, link and meta (real world example - paging (20 identities, links for more data and some meta with paging info)).
The lib currently supports all these combinations. Which is good. But I want moar 😄 I want to be able to

  • include some resources + links + paging meta when resource is main
  • keep only link to relationship data when resource is within included

something like this

{
    "data" : {
        "type" : "posts",
        "id"   : "1",
        "attributes" : {
            "..."
        },
        "relationships" : {
            "comments" : {
                "data" : [
                    { "type":"comments", "id":"5" }
                ],
                "links" : [
                    "<paging links for the rest of data here>"
                ],
                "meta" : {
                    "total-pages": "...",
                    "page-size": "..."
                }
            }
        }
    },
    "included" : [{
        "type"  : "comments",
        "id"    : "5",
        "attributes" : {
            "..."
        },
        "relationships" : {
            "replies" : {
                "links" : {
                    "self" : "<only link here, no identities when resource is included>"
                }
            }
        }
    }]
}
@neomerx
Copy link
Owner Author

neomerx commented Mar 24, 2016

Main change in Schema. Instead of

public function getRelationships($comment, array $includeList = []);

it should be declared as

public function getRelationships($comment, $isPrimary, array $includeList)

new parameter $isPrimary informs if $comment will be put into primary data section rather than included.

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

No branches or pull requests

1 participant