Skip to content

Commit b856b71

Browse files
vincentchalamonmeyerbaptiste
authored andcommitted
Update doc from new PR
1 parent 3a1afe1 commit b856b71

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

core/default-order.md

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Override default order
1+
# Override Default Order
22

33
API Platform Core provides an easy way to override default order in your collection.
44

@@ -11,26 +11,77 @@ By default, it will order by resource identifier(s) using ASC direction. If you
1111

1212
namespace AppBundle\Entity;
1313

14-
use ApiPlatform\Core\Annotation\ApiProperty;
1514
use ApiPlatform\Core\Annotation\ApiResource;
1615

1716
/**
18-
* @ApiResource(attributes={"order"={"foo", "ASC"}})
17+
* @ApiResource(attributes={"order"={"foo": "ASC"}})
1918
*/
2019
class Book
2120
{
2221
// ...
2322

2423
/**
2524
* ...
26-
* @ApiProperty()
2725
*/
2826
public $foo;
2927
}
3028
```
3129

32-
This `order` attribute is used as an array with 2 entries: the first one defines the order field, the second one defined the direction.
33-
If you only specify the first one, `ASC` direction will be used as default.
30+
This `order` attribute is used as an array: the key defines the order field, the values defines the direction.
31+
If you only specify the key, `ASC` direction will be used as default. For example, to order by `foo` & `bar`:
32+
33+
```php
34+
<?php
35+
36+
// src/AppBundle/Entity/Book.php
37+
38+
namespace AppBundle\Entity;
39+
40+
use ApiPlatform\Core\Annotation\ApiResource;
41+
42+
/**
43+
* @ApiResource(attributes={"order"={"foo", "bar"}})
44+
*/
45+
class Book
46+
{
47+
// ...
48+
49+
/**
50+
* ...
51+
*/
52+
public $foo;
53+
54+
/**
55+
* ...
56+
*/
57+
public $bar;
58+
}
59+
```
60+
61+
It's also possible to configure the default filter on an association property:
62+
63+
```php
64+
<?php
65+
66+
// src/AppBundle/Entity/Book.php
67+
68+
namespace AppBundle\Entity;
69+
70+
use ApiPlatform\Core\Annotation\ApiResource;
71+
72+
/**
73+
* @ApiResource(attributes={"order"={"author.username"}})
74+
*/
75+
class Book
76+
{
77+
// ...
78+
79+
/**
80+
* @var User
81+
*/
82+
public $author;
83+
}
84+
```
3485

3586
Previous chapter: [Configuration](configuration.md)
3687

0 commit comments

Comments
 (0)