Skip Menu |

This queue is for tickets about the Mojolicious-Plugin-JSONAPI CPAN distribution.

Report information
The Basics
Id: 125937
Status: resolved
Priority: 0/
Queue: Mojolicious-Plugin-JSONAPI

People
Owner: ZIALI [...] cpan.org
Requestors: pspencer [...] fields.utoronto.ca
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Change (v2.1) to self/related links in relationships: is it really correct?
Date: Thu, 26 Jul 2018 14:33:00 -0400 (EDT)
To: Ali Zia via RT <bug-Mojolicious-Plugin-JSONAPI [...] rt.cpan.org>
From: Philip Spencer <pspencer [...] fields.utoronto.ca>
Hi, Are you sure the change you introduced in "Fix bug where the relationship links were pointing to their origin in "related" and to their relationships link in "self", should have been the opposite" is really correct? On my reading of the JSON API spec, it was correct the way it was and wrong now. For example, in http://jsonapi.org/format/#document-resource-object-linkage it gives the following example: / ... { "type": "articles", "id": "1", "attributes": { "title": "Rails is Omakase" }, "relationships": { "author": { "links": { "self": "http://example.com/articles/1/relationships/author", "related": "http://example.com/articles/1/author" }, "data": { "type": "people", "id": "9" } } }, "links": { "self": "http://example.com/articles/1" } } // ... In the relationships object, the "self" link is meant to get you the "relationship object" -- that is, the specification of the linkage between the article and the author -- and the "related" link is meant to get you the related resource ... that is, "http://example.com/articles/1/author" would give you the same resource as "http://example.com/people/9". So when building a "links document" (relationship object) in the way illustrated in the JSON API examples, shouldn't the relationship object have a "self" link that points to the relationship object (that is, the URL with the word 'relationships' in it) and a "related" link that does not have the word 'relationships' in it and points to the related resource rather than to the links document itself? Now I don't think the json api spec mandates what those URLs have to be, only what they should return, so I suppose one could build an API where $resource/relationships/$id returned the related resource and $resource/$id returned the links document, but that would not be consistent with the examples given in the format specification. I think the way you had it before was consistent with the specification. Best regards, Philip On Thu, 7 Jun 2018, Ali Zia via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=125504 > > > Thank you for the bug report, this is patched in 1.6. > > For some reason I was thinking length would return the number of items > in the array :S >
--------------------------------------------+------------------------------- Philip Spencer pspencer@fields.utoronto.ca | Director of Computing Services Room 167 (416)-348-9710 ext5067 | The Fields Institute for 222 College St, Toronto ON M5T 3J1 Canada | Research in Mathematical Sciences
Hi Philip, Apologies its taken me so long to look into this. You are correct, it was correct the first time around. I will look at patching this soon
On Sat Jan 12 12:35:44 2019, ZIALI wrote: Show quoted text
> Hi Philip, > > Apologies its taken me so long to look into this. > > You are correct, it was correct the first time around. I will look at > patching this soon
Looking at the specification again, both links seem to behave the same. Neither contain the context of the relationship in question i.e. they don't specify the ID of the relationship in the URL (neither for belongs_to or has_many). I will continue with the change, as well as add an (optional?) URL to be created for both links in the Mojo plugin (currently it only supports the self route).
This has been updated in v2.4 Thanks for the feedback!
Subject: Re: [rt.cpan.org #125937] Change (v2.1) to self/related links in relationships: is it really correct?
Date: Mon, 14 Jan 2019 17:20:27 -0500 (EST)
To: Ali Zia via RT <bug-Mojolicious-Plugin-JSONAPI [...] rt.cpan.org>
From: Philip Spencer <pspencer [...] fields.utoronto.ca>
Dear Ali, Thanks for looking into it! I do not believe both links behave the same; they behave similarly if you GET them (except the "related" link has more information, the full content of the related object, where as the "self" link simply specifies the type and id of the related object) but they behave very differently if you DELETE them: DELETE http://example.com/articles/1/relationships/author (the "self" link) would remove the "author" relationship between article 1 and person 9 but leave person 9 intact, whereas DELETE http://example.com/articles/1/author (the "related" link) I believe would have the same effect as DELETE http://example.com/people/9 -- it would actually delete the person record with id 9. Best regards, Philip On Sat, 12 Jan 2019, Ali Zia via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=125937 > > > On Sat Jan 12 12:35:44 2019, ZIALI wrote:
>> Hi Philip, >> >> Apologies its taken me so long to look into this. >> >> You are correct, it was correct the first time around. I will look at >> patching this soon
> > > Looking at the specification again, both links seem to behave the same. > Neither contain the context of the relationship in question i.e. they > don't specify the ID of the relationship in the URL (neither for > belongs_to or has_many). > > I will continue with the change, as well as add an (optional?) URL to be created for both links in the Mojo plugin (currently it only supports the self route). >
--------------------------------------------+------------------------------- Philip Spencer pspencer@fields.utoronto.ca | Director of Computing Services Room 167 (416)-348-9710 ext5067 | The Fields Institute for 222 College St, Toronto ON M5T 3J1 Canada | Research in Mathematical Sciences