Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
API Create orderBy() method to handle raw SQL #10600
API Create orderBy() method to handle raw SQL #10600
Changes from all commits
ae4d7fa
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will still match against something like
"Column Name"
- it's funtionally equivalent to usingexplode
for any string with only one space in it.If the column name has a space in it, and no direction was supplied, it should not match here so that the default direction can be added in the
else
block.I think we should explicitly be checking for
asc
anddesc
here instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't match
"Column Name"
- it's pinned with$
at the end of the regexIt would match
Column Name
- however this will fail onvalidateSortDirection()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, I should have omitted the quote marks which were intended to mean "this is the whole string"
My point is that it shouldn't fail on
validateSortDirection()
, becauseColumn
on its own won't fail that.So currently passing
Column
is fine butColumn Name
is not fine, even if they're both valid columns.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think think we need to over think for edge cases like this. An exception will still be thrown and it should be pretty obvious at that point they need to wrap their column in quotes since they'll get a 'Invalid sort direction Name' exception message
Even if we change this to
(asc|desc)
, then it'll still fail on the edge case of someone calling naming columnMySortDir ASC
. There's a workaround available which is to wrap the weird column in double quotes e.g.->sort('"Column Name" ASC')
I think it's reasonable to put the onus on end users to do this here - they'll be well used to do extra steps to get things to actually work. Other parts of Silverstripe will already be broken e.g. calling $myDataObject->{'Column Name'} to get values (I'm assuming that actually works)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree but I'll merge it 'cause it's not worth arguing about. Someone can raise an issue when it causes problems for them.