Skip to content

Fix 1246: configure default order on ApiResource annotation #1321

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

Merged
merged 2 commits into from
Aug 22, 2017
Merged

Fix 1246: configure default order on ApiResource annotation #1321

merged 2 commits into from
Aug 22, 2017

Conversation

vincentchalamon
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #1246
License MIT
Doc PR api-platform/docs#235

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature, thanks!! I just left a small comment.


public function __construct(string $order = null)
public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, string $order = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This a BC break, can you add it as an optional last parameter?

@Simperfit
Copy link
Contributor

Could you please rebase instead of merging ?

@dunglas dunglas merged commit f6ccfff into api-platform:master Aug 22, 2017
@dunglas
Copy link
Member

dunglas commented Aug 22, 2017

Thank you @vincentchalamon

@vincentchalamon vincentchalamon deleted the issues/1246 branch August 22, 2017 07:49
* @author Vincent Chalamon <[email protected]>
*
* @ApiResource(attributes={
* "order"={"name", "DESC"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably have been too fast to merge. Wouldn't be better to allow complex ordering? I suggest the following:

@ApiResource(attributes={"name": "DESC", "firstname": "ASC"})

(Order by name then by firstname). WDYT @vincentchalamon? Can you do a follow up PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though about adding the multiple default ordering, but I wasn't sure it was very useful.
I would prefer a syntax like that:

@ApiResource(attributes={
    "order"={"name": "DESC", "firstname": "ASC"}
})

WDYT @dunglas? If so, I could open another PR to fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's useful (ordering by name then firstname is very common for instance). You're right for the syntax, my example is faulty (missing order key). A PR would be great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahmed-bhs
Copy link
Contributor

Guys thank you for this feature, does this support yaml configuration, I tried to add order to my resource, seems nothing work ! Any idea? @vincentchalamon

resources:
    App\Entity\Repos\EventFamily:
        collectionOperations:
            get:
                order: ["name", "DESC"]
                attributes:
                    order: ["name", "DESC"]

@vincentchalamon
Copy link
Contributor Author

vincentchalamon commented Oct 20, 2020

@ahmed-bhs Did you try the following configuration?:

resources:
    App\Entity\Repos\EventFamily:
        attributes:
            order: ["name", "DESC"]
        collectionOperations:
            get: ~

I didn't try this configuration in YAML since many years (this PR is older than 3 years).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants