Skip to content

Links in Schema #119

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 23, 2016 · 3 comments
Closed

Links in Schema #119

neomerx opened this issue Mar 23, 2016 · 3 comments
Assignees
Milestone

Comments

@neomerx
Copy link
Owner

neomerx commented Mar 23, 2016

It would be nice to have an ability to create related relationship links from Schema. It could be used for pagination in relationships. Also the code could be reused from Encoder which has similar methods withRelationshipRelatedLink and withRelationshipSelfLink.

@lindyhopchris
Copy link
Collaborator

@neomerx

Don't know if this is related, but there is a need to be able to reconstruct links from the parameters that were received from the client.

As an example, for pagination the links returned in the document level for pagination may need to include the filtering parameters because the client might be paging over filtered resources.

I've got a feature/pagination branch on my laravel-json-api package and I'm having to do this at the moment:

https://github.com/cloudcreativity/laravel-json-api/blob/feature/pagination/src/Schema/PaginationLink.php

Don't know what you think about adding to your package the ability to reconstruct links?

@neomerx
Copy link
Owner Author

neomerx commented Mar 23, 2016

@lindyhopchris that's my solution for links reconstruction. Currently it works with main data and I'd like to reuse it for data in relationships too. This feature is a part of solution.

Btw have a look at new limoncello-shot

neomerx added a commit that referenced this issue Mar 24, 2016
@neomerx neomerx added fixed and removed in progress labels Mar 24, 2016
@neomerx
Copy link
Owner Author

neomerx commented Mar 24, 2016

I've spotted and fixed lib design issue while working on this. In Schema relationship it was possible to set links which would appear in json api document (example below)

{
    "data" : {
        "type"  : "posts",
        "id"    : "1",
        "attributes" : {
            "title" : "...",
            "body"  : "..."
        },
        "relationships" : {
            "comments" : {
                "links" : { "boo" : "http://example.com/posts/1/another/link" }
            }
        }
    }
}

The problem was that /posts/1/ part was fixed. The lib added it to all links with $treatAsHref = false. So a) it was inflexible b) link URLs were not truly URLs but only a part of it (without /posts/1/)

I got rid of it. However for some cases (I believe it's rarely used) it will cause incompatibility. Solution is simple. Instead of

'boo' => new Link('another/link'),

link should be defined in Schema as

'boo' => new Link($this->getSelfSubUrl($post) . '/another/link'),

@neomerx neomerx added the BC label Mar 24, 2016
@neomerx neomerx added this to the 0.8.0 milestone Mar 24, 2016
@neomerx neomerx self-assigned this Mar 25, 2016
@neomerx neomerx removed the fixed label Mar 25, 2016
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

2 participants