Skip to content
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

Relationship result sorting #5648

Closed
toto975 opened this issue Aug 8, 2022 · 4 comments
Closed

Relationship result sorting #5648

toto975 opened this issue Aug 8, 2022 · 4 comments

Comments

@toto975
Copy link
Contributor

toto975 commented Aug 8, 2022

Laravel version

9.7.0

PHP version

8.1.4

Voyager version

1.5

Database

8.0.28

Description

In a select dropdown relationship, datas are not sorting as defined in the sort option of the relationship

Steps to reproduce

My Model : Parcours belongsto Cadre, with a sort on the name
image

When adding a Parcour, the select dropdown loads datas 50 by 50
(I show the json results)
Page 1
image
Page 2
image
Page 3
image

It seems that datas are sorted by id, then by name for Page 1 and 2
By name then by id on page 3.

Expected behavior

The relation datas must be sorted by 'name' first, then take/limit and skip/offset.

In voyagerBaseController->relation, some changes since this fixe #4858 to include sorting
But sorting is done after take/limit and skip/offset.

For sample, line 928
$relationshipOptions = $model->take($on_page)->skip($skip)->get();
and line 945
$relationshipOptions = $relationshipOptions->sortBy($options->sort->field);

I tried
$relationshipOptions = $model->get()->sortBy($options->sort->field)->take($on_page)->skip($skip);

It's OK for Page 1, the first 50 datas are sorted by name, but next pages are empty.

I think there is some changes to do between line 911 and 947.

Screenshots

No response

Additional context

No response

@ben-cheng565
Copy link

@toto975 Can I try to work this issue out?

@toto975
Copy link
Contributor Author

toto975 commented Nov 23, 2022

Certainly you can
Great if you find the fix.

@toto975
Copy link
Contributor Author

toto975 commented Dec 13, 2022

It's fixed with #5695

@toto975 toto975 closed this as completed Dec 13, 2022
@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants