8000 Ordering of primary data by hhware · Pull Request #473 · json-api/json-api · GitHub
[go: up one dir, main page]

Skip to content

Ordering of primary data #473

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

Conversation

hhware
Copy link
Contributor
@hhware hhware commented Mar 16, 2015

IMHO, not enough attention is given in the spec to the way of specifying of order of results in the response, especially given that the specification of sorting in the request is quite detailed. I believe it is just assumed that the way to specify order of results is to order elements in the top-level data, but AFAIK it is not mentioned explicitly anywhere. The only reference to ordering I was able to find is in the Recommendations: "because order is significant" . I suggest to mention this explicitly in the base spec.

@hhware
Copy link
Contributor Author
hhware commented Mar 28, 2015

I would like to request to consider this for 1.0.

@ethanresnick
Copy link
Member

Note that merging this would make supporting sorting non-optional, which is a change from what we currently have. (Right now, the spec says "A server MAY choose to support requests to sort resource collections".)

Making sort support mandatory could be a good thing anyway because, right now, a generic client has no way to know whether their sort request was honored. The other solution is to leave sorting optional, but require servers to state whether they support it by making it an extension. I've discussed that problem/possibility more in #460.

@hhware hhware force-pushed the ordering-of-primary-data-and-to-many-relationship-linkage-objects branch from b656461 to ddbc46f Compare March 28, 2015 16:18
@hhware
Copy link
Contributor Author
hhware commented Mar 28, 2015

@ethanresnick, thanks for pointing this out! The intention of this PR was not to make sorting non-optional, but to explicitly define ordering in the response, so I corrected it.

@ethanresnick
Copy link
Member

Cool!

I think the PR should also specify how the sorts would be applied to the to-many relationships, as that's a little vague.

@hhware hhware force-pushed the ordering-of-primary-data-and-to-many-relationship-linkage-objects branch from ddbc46f to 0a9ddc6 Compare March 28, 2015 19:02
@hhware
Copy link
Contributor Author
hhware commented Mar 28, 2015

@ethanresnick, thanks again for pointing it out! I actually did not suggest that sorting could possibly apply to relationships, that sentence was only about ordering. Corrected again.

@ethanresnick
Copy link
Member

@hhware, After thinking about this more, I don't think sorts should be able to order the to-many relationship linkage at all (at least not for 1.0), but rather only the resources themselves in a collection. This is what the spec currently specifies, and it's probably not worth changing. So ignore my comment about the vagueness. I'd now suggest removing the text and note about to-many linkage objects all together. After that, I'm +1 on this PR!

@hhware
Copy link
Contributor Author
hhware commented Mar 31, 2015

@ethanresnick, I do not quite understand your point. This PR is not about sorting directive in the request, it is about ordering of objects in the response. If the to-many relationship is stored in the database in ordered form (i.e., it is stored in a separate table with a column order_number INT), the server may return them in that order. The suggested MAY is only saying that the order of linkage objects in the array may indeed be a representation of an ordered relationship, similar to order of elements in primary data in the absence of sort may reflect default ordering used by the server.

@ethanresnick
Copy link
Member

Ahh, ok, I understand now!

As far as the ordered relationships go: saying even that the relationship entries could represent an ordered list seems inconsistent with the other places in the spec where we're currently saying that set semantics apply (e.g. when POSTing to or DELETEing from a to-many relationship).

I'm tentatively in favor of treating relationships as lists rather than sets, which would allow for repeated entries and for order to matter, but I think that discussion would have to happen in a separate issue or PR, since it's a big change. Meanwhile, while the current (if implicit) set-based definition is implicit, I still think the note about ordering doesn't belong.

@hhware hhware changed the title Ordering of primary data and to-many relationship linkage objects Ordering of primary data Mar 31, 2015
@hhware hhware force-pushed the ordering-of-primary-data-and-to-many-relationship-linkage-objects branch from 0a9ddc6 to 3a44c1d Compare March 31, 2015 19:43
@hhware
Copy link
Contributor Author
hhware commented Mar 31, 2015

@ethanresnick, I agree with you. I will work on addressing ordering of relationships elsewhere. Updated.

@ethanresnick
Copy link
Member

Cool. This looks good to me now!

@tkellen
Copy link
Member
tkellen commented Apr 6, 2015

👍 to merge this PR as is.

dgeb added a commit that referenced this pull request Apr 7, 2015
…any-relationship-linkage-objects

Ordering of primary data
@dgeb dgeb merged commit 4a4f89d into json-api:gh-pages Apr 7, 2015
@dgeb
Copy link
Member
dgeb commented Apr 7, 2015

Thanks @hhware :shipit:

FWIW, I just moved the other paragraph that covers support for sorting closer to this one. See 12d5708

@hhware
Copy link
Contributor Author
hhware commented Apr 7, 2015

how the sorts would be applied to the to-many relationships

@ethanresnick, a way to sort relationship linkage object arrays is proposed in #431 (comment)

@hhware hhware deleted the ordering-of-primary-data-and-to-many-relationship-linkage-objects branch April 7, 2015 14:42
@hhware hhware mentioned this pull request Apr 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0