-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Add orderByPriority Method for Custom Sorting in Query Builder V2 #52535
base: 11.x
Are you sure you want to change the base?
Changes from 3 commits
17397ba
567959d
98209d5
89acedc
cbf0bbe
2f0658b
295b682
fa7f046
e79e50a
c8fe807
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,4 +524,19 @@ protected function wrapJsonBooleanSelector($value) | |
|
||
return 'json_extract('.$field.$path.')'; | ||
} | ||
|
||
/** | ||
* Apply custom ordering to a query based on a priority array. | ||
* | ||
* @param $column | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The grammars are missing the parameter types for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated the code to add the type for column and direction |
||
* @param array $priority | ||
* @param $direction | ||
* @return string | ||
*/ | ||
public function orderByPriority($column, array $priority, $direction = 'asc') | ||
{ | ||
$placeholders = implode(',', array_fill(0, count($priority), '?')); | ||
|
||
return "FIELD($column, $placeholders) $direction"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The column name needs to be wrapped with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have applied the wrap function on all grammars and updated the tests accordingly. |
||
} | ||
} |
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.
You can remove this implementation:
MariaDbGrammar
extendsMySqlGrammar
and inherits the method from there.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.
Correct. I have removed the code from MariaDbGrammar.