-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix api-platform/core #1246: configure default order on ApiResource annotation #235
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
Fix api-platform/core #1246: configure default order on ApiResource annotation #235
Conversation
core/default-order.md
Outdated
@@ -0,0 +1,37 @@ | |||
# Override default order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about naming the file order.md
or ordering.md
and merging everything related to ordering (the global config option, the filter and this config option) in this file?
It will be easier to understand for a new comer IMP.
Btw the title must be in Title Case (Override Default Order
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't explain this default order in the order filter cause it's a different feature. I better think we should mention it in the order filter and in the global config option, but keep it separated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO having a specific doc for all ordering features would be better in term of understanding for a newcomer, it was my point.
core/default-order.md
Outdated
@@ -0,0 +1,37 @@ | |||
# Override default order | |||
|
|||
API Platform Core provides an easy way to override default order in your collection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of the collections
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get rid of Core
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of the collections
Why plural?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took Core
keyword from many .md
files in this project. If we get rid of it, please open a new PR to remove it everywhere.
core/default-order.md
Outdated
|
||
API Platform Core provides an easy way to override default order in your collection. | ||
|
||
By default, it will order by resource identifier(s) using ASC direction. If you want to customize this order, you must add an `order` attribute on your ApiResource annotation: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, it will order by resource identifier(s) using ASC direction.
IIRC, it's not true. By default don't change the order of the underlying DBMS, and it is not defined nor consistent: https://dba.stackexchange.com/a/6053
@ApiResource
annotation. Maybe it is worth mentioning that it can also be configured using XML and YAML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Bridge/Doctrine/Orm/Extension/OrderExtension
default order collection by identifier(s): https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/Extension/OrderExtension.php#L56
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok it's a bit more complicated. It's ordered by default only if you use the Symfony bridge (https://github.com/api-platform/core/blob/master/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php#L92), if you use the class directly, $this->order
is null
and the collection isn't ordered: https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/Extension/OrderExtension.php#L54
But ok to keep it as is.
core/default-order.md
Outdated
use ApiPlatform\Core\Annotation\ApiResource; | ||
|
||
/** | ||
* @ApiResource(attributes={"order"={"foo", "ASC"}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dunglas Could it be interesting to configure a default order by an association, like author.username
?
core/default-order.md
Outdated
|
||
/** | ||
* ... | ||
* @ApiProperty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This annotation is useless, you can remove it.
core/default-order.md
Outdated
} | ||
``` | ||
|
||
It's also possible to configure the default filter on an association property: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this part? So we can merge your PR. We will add it when the api-platform/core#1324 will be merged.
…piResource annotation
core/default-order.md
Outdated
|
||
API Platform Core provides an easy way to override default order in your collection. | ||
|
||
By default, it will order by resource identifier(s) using ASC direction. If you want to customize this order, you must add an `order` attribute on your ApiResource annotation: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, items in the collection are ordered in ascending (ASC) order by their resource identifier(s).
core/default-order.md
Outdated
@@ -0,0 +1,88 @@ | |||
# Override Default Order | |||
|
|||
API Platform Core provides an easy way to override default order in your collection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... override the default order of items in your collection.
c0f56b3
to
3207dfd
Compare
3207dfd
to
208eb03
Compare
Thanks @vincentchalamon, don't forget to add the removed paragraph when api-platform/core#1324 will be merged: It's also possible to configure the default filter on an association property:
<?php
// src/AppBundle/Entity/Book.php
namespace AppBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
/**
* @ApiResource(attributes={"order"={"author.username"}})
*/
class Book
{
// ...
/**
* @var User
*/
public $author;
} |
No description provided.