-
-
Notifications
You must be signed in to change notification settings - Fork 927
Closed
Labels
Description
By default, API Platform order list by resource identifier. The only way to default order list by another field would be to create a custom extension, and if the filter is not defined in url apply a default order.
For example:
$request = $this->requestStack->getCurrentRequest();
--
if (null === $request || !$request->query->has('foo')) {
// Default order
$queryBuilder->orderBy($queryBuilder->getRootAliases()[0].'.bar ASC');
return;
}
// Custom order from request
$queryBuilder->orderBy($queryBuilder->getRootAliases()[0].'.bar DESC');
But it could be interesting to configure it directly from the @ApiResource
annotation declaration, like:
/**
* @ApiResource(attributes={"order"={"bar"="DESC"}})
* @ORM\Entity()
*/
class Foo
{
/**
* @var int
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var int
*
* @ORM\Column()
*/
private $bar;
}
@api-platform/core-team do you think it could be interesting?
teohhanhui, JarJak, ghindle, Perni1984, dunglas and 1 more