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

WIP: FIX Implement localisable order by clause to support translatable sorting #415

Merged

Conversation

robbieaverill
Copy link
Contributor

@robbieaverill robbieaverill commented May 18, 2018

Resolves #208

@robbieaverill
Copy link
Contributor Author

robbieaverill commented May 18, 2018

I've implemented a rough looking fix to allow localisable sort conditions in the same way that localisable where conditions work at the moment. There's a test failure in testWritesToCurrentLocale which looks to be pre-existing (tested locally on 4.1, re-running the last 4.1 build on Travis now). Edit: 4.1 build passed again, strange.

@tractorcow would be good to get your eyes over this when you're back from your holiday =)

@robbieaverill robbieaverill changed the title Add tests for localised sorting support WIP: Add tests for localised sorting support May 21, 2018
@robbieaverill
Copy link
Contributor Author

Ok so the tests I added in the first commit broke the testWritesToCurrentLocale test - I'll work out why and push an update

@robbieaverill robbieaverill changed the title WIP: Add tests for localised sorting support FIX Implement localisable order by clause to support translatable sorting May 31, 2018
$foundInConditionSearch = false;
foreach ($conditionSearch as $conditionSearchOption) {
if (preg_match(
'/^"(?<table>[\w\\\\]+)"\."(?<field>' . trim($column, '"') . ')"$/i',
Copy link
Collaborator

Choose a reason for hiding this comment

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

If $column fails the above regexp, I think assuming that it's a basic column name is a bit risky. It could be a non-trivial sub-query, or it could be a composite sort. The else should really be another regexp that is similar but doesn't require the table prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, do you have a couple of examples that I could add to the tests?

Copy link
Collaborator

Choose a reason for hiding this comment

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

like $list->sort('"Title", "Content"')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sweet. We can't really make subqueries fluent in this case though right...?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right so you should skip them.

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've added a bunch more tests, the last commit contains some tests that I've got no idea how to write logic for to make them pass 😆

Also I'm a bit iffy about some of the tests in the "Add more sorting tests" commit because they're relying on the DB to return natural sort orders when the sorting isn't specific enough to always return a definite order - the fixtures have common values in them (deliberately) but maybe we either need to remove the common values to ensure that there's a predictable sort order at all times.

@robbieaverill robbieaverill changed the title FIX Implement localisable order by clause to support translatable sorting WIP: FIX Implement localisable order by clause to support translatable sorting Jun 5, 2018
@tractorcow tractorcow force-pushed the pulls/4.1/allow-sorting branch from a449e8b to 0be2919 Compare July 13, 2018 05:00
@tractorcow
Copy link
Collaborator

Pushed up some fixes @robbieaverill

@tractorcow
Copy link
Collaborator

Pushed up linting fixes @robbieaverill but there are still some small issues to fix.

@tractorcow tractorcow merged commit 252e489 into tractorcow-farm:4.1 Jul 16, 2018
@tractorcow tractorcow deleted the pulls/4.1/allow-sorting branch July 16, 2018 21:09
@chrispenny
Copy link

I'm late to the party on this one, but please accept my delayed:
Thank you! I appreciate your work (as always)!

@lerni
Copy link

lerni commented Aug 23, 2018

If you experience this issue with SS 3.x theres a composer installable patch https://github.com/lerni/silverstripe3-mysql57-fluent

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