-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
fix mode 1 sorting by flag for multiple fields #1536
Conversation
|
You are right that the current logic is incorrect. However, your fix does not seem to fix it. Contao considers two flags, the … ORDER BY date_start DESC, date_stop DESCSo now the question remains why there is an additional |
|
You're right, as my test cases were dates (and thus had I've updated the PR to also take
Additionally, thinking a bit about it, I'm not sure why this is limited to mode 1, shouldn't mode 2 (and mode 3, but that is broken beyond repair, afair) also respect the sorting directions defined in the dca? |
Probably yes. Regarding the priority in your implementation: Shouldn't the @contao/developers /cc |
I'm not sure. In https://github.com/contao/core-bundle/blob/4.4/src/Resources/contao/drivers/DC_Table.php#L4367 and https://github.com/contao/core-bundle/blob/4.4/src/Resources/contao/drivers/DC_Table.php#L4855 |
|
@patrickjDE We have tried to discuss this in Mumble on January 27th, however we do not really see a valid use-case. Can you elaborate on your use-case please? |
|
Well, the actual use-case is simple: Sort a mode 1 dca by two fields, both descending. IMO a valid use-case, especially for dates. I do realize that it is currently possible to achieve the desired result with explicitly defining the sorting SQL, but both ways to get there are counter-intuitive and IMO semantically wrong:
|
|
are we gonna merge/fix this at all or close the PR? |
|
@aschempp That depends on whether or not you (or rather we) consider Patrick's use case to be valid or not. 🤓 |
As discussed in Mumble on June 6th, this is a bug. We have to add an core-bundle/src/Resources/contao/drivers/DC_Table.php Lines 4675 to 4678 in f9eb38b
|
|
That would fix the sql syntax bugs, but setting |
|
You are right. We have to move the whole |
|
Eventually fixed in contao/contao@fc9a686. Thank you @patrickjDE. |
WIth the following dca configuration
I'd expect the records to be sorted first descending by
date_startthen descending bydate_stop, instead they are sorted ascending bydate_startand descending bydate_stop.This is caused by https://github.com/contao/core-bundle/blob/4.4/src/Resources/contao/drivers/DC_Table.php#L4664 where the SQL for the sorting direction is only added once at the end, instead of being added to every field.
This PR fixes this issue by setting the sorting for each field according to the chosen flag, except where it was set explicitly (e.g.
'fields' => ['date_start', 'date_stop ASC'],).It also fixes an SQL syntax error when neither sorting fields nor sorting flag are given (
DESCwas added to the query string, although there was noORDER BY ...part).Futher it fixes another SQL syntax error, when an even flag or no flag at all is given, and the last field has its sorting set explicitly (
DESCwas added twice in this case).