-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
API: Order parameter #5602
Comments
refs TryGhost#5727, TryGhost#5602 - refactored to maintain the order in which tags are added - will require a further, more complex refactor to handle re-ordering
refs TryGhost#5727, TryGhost#5602 - Add new 'order' column to posts_tags table - Migrate all existing posts_tags to have a correct value for 'order' - Rewrite updateTags to not remove all tags, and to correctly maintain order - Add transaction support for tag operations - Many tests
refs TryGhost#5727, TryGhost#5602 - Add new 'order' column to posts_tags table - Migrate all existing posts_tags to have a correct value for 'order' - Rewrite updateTags to not remove all tags, and to correctly maintain order - Add transaction support for tag operations - Many tests
I think it would be better, if we did not force spaces between rules. This will cause errors among developers, because they normally don't expect, that a lack of space in url can cause an error. I think we should accept both types of inputs, with and without spaces. And not being strict on lower/upper case should also be a plus. Ideally, these should be treated equally: |
Yes I think it needs to so that it will play nicely with joins? |
Ok, then |
Note: There are one or two 'hard' problems here when it comes to ordering by counts. Counts aren't implemented yet and so the open PR can be merged without support for that, but I'm just thinking out loud about what the solution might look like. There is one, cheeky line of ordering code in the stuff I added to make filters work: https://github.com/TryGhost/Ghost/blob/master/core/server/models/base/utils.js#L52 It's hardcoded atm, but what it is supposed to is replace the default sort order automatically when a query is made asking for all posts which match more than one tag. This is the special rule for 'IN' defined in here: #5604. It should still be possible to override this. The problem is, that to order by a count you have to call The API for ordering by a count would still be e.g. This is probably a separate issue - just brain-dumping :) |
@ErisDS Turns out bookshelf is prefixing attributes with table names automatically. This happened when I added table prefixes: Update: Now I found out that we prefix attributes, not bookshelf: https://github.com/TryGhost/Ghost/blob/master/core/server/models/base/pagination.js#L171 |
I was just about to reply and say, I think this was done by the order-handling code in the pagination plugin and it probably needs updating to only add the table prefix if it is not already present. |
I'm closing most API issues temporarily with the JSON API Overhaul & OAuth access are currently scheduled next on the roadmap |
As mentioned in #5463, we want to add a new
order
top-level parameter to API browse requests.The
order
parameter allows a user to specify which order they'd like their results to be returned in.The default orders across the 3 key resources are currently:
"posts"."status" ASC, "posts"."published_at" DESC, "posts"."updated_at" DESC, "posts"."id" DESC
"users"."last_login" DESC, "users"."name" ASC, "users"."created_at" DESC
The
order
parameter should accept any valid SQL order by clause, which does not contain quote marks, e.g.users.last_login DESC, users.name ASC, users.created_at DESC
. The comma-space separator between rules, and the space separator between property and direction are required.This means that a valid value for the
order
parameter can be validated to contain only alphanumeric characters, dots, underscores and spaces, with the property being any string with those characters (except the space), and the direction is always eitherASC
orDESC
(upper or lower) It should be possible to design a regex to match this pattern.The
order
parameter should also validate that the provided order properties are valid attributes for the model. Any field with doesn't specify which model it belongs to should default to whichever model is being queried, and this should be set explicitly.It should be possible to translate this format into a JSON format that matches the one returned from
orderDefaultOptions
using a split on the comma and space. The model must be included for each property (this will be added to models soon).E.g. for posts, the default order would be translated to the following JSON objet:
That object can then be used to apply the order, much as is already done, by reading
options.order
, and using the value oforderDefaultOptions
if it doesn't exist: https://github.com/TryGhost/Ghost/blob/master/core/server/models/base/index.js#L293The text was updated successfully, but these errors were encountered: