Give resource more control over sortable fields#1002
Merged
lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom Mar 21, 2017
rfb:resource_sortable_field
Merged
Give resource more control over sortable fields#1002lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom rfb:resource_sortable_field
lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom
rfb:resource_sortable_field
Conversation
I'm in a situation where I want clients to have repeatable, random sort order on a collection. My solution is to pass a ?sort=rand-N, with N being the seed used for sorting. This way, if the client was to page through the list or link to the list, the sort order would be preserved. For example, `/providers?sort=rand-42` would apply a random sort order with 42 as the key. To accommodate this, I need JSONAPI::RequestParser to allow sort keys that are not in a predetermined list. I think a good solution to this would be to have the RequestParser defer to the Resource when checking if a sort key is valid. The existing behaviour is maintained by moving the check on sortable_fields to sortable_field?, which can be overloaded by application specific resource classes.
Contributor
Author
|
related PR for the guides: https://github.com/cerebris/jsonapi-resources-site/pull/6/files |
Contributor
|
@rfb Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm in a situation where I want clients to have repeatable, random sort
order on a collection. My solution is to pass a ?sort=rand-N, with N
being the seed used for sorting. This way, if the client was to page
through the list or link to the list, the sort order would be preserved.
For example,
/providers?sort=rand-42would apply a random sort orderwith 42 as the key.
To accommodate this, I need JSONAPI::RequestParser to allow sort keys
that are not in a predetermined list. I think a good solution to this
would be to have the RequestParser defer to the Resource when checking
if a sort key is valid.
The existing behaviour is maintained by moving the check on
sortable_fields to sortable_field?, which can be overloaded by
application specific resource classes.
I will write some tests and docs if this approach is acceptable to the
maintainers.