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

Orderby ability #9

Closed
wants to merge 14 commits into from
Closed

Orderby ability #9

wants to merge 14 commits into from

Conversation

valinurovam
Copy link
Contributor

Hi all.
Im tried to add orderby ability for yii2-redis. It works for me. Review please.

@@ -369,6 +365,19 @@ protected function executeScript($db, $type, $columnName = null)
*/
private function findByPk($db, $type, $columnName = null)
{
if (!empty($this->orderBy) and in_array($type, ['All', 'One', 'Count', 'Column'])) {
Copy link
Member

Choose a reason for hiding this comment

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

and&&

@cebe
Copy link
Member

cebe commented Apr 26, 2015

really cool, will check it in detail later.

Could you add some unit tests? At least these two functions should be removed, which will add tests for some sorting:
https://github.com/yiisoft/yii2-redis/blob/master/tests/ActiveRecordTest.php#L146-L154

@cebe cebe added this to the 2.0.x milestone Apr 26, 2015
@cebe cebe self-assigned this Apr 26, 2015
@cebe cebe added the type:enhancement Enhancement label Apr 26, 2015
@valinurovam
Copy link
Contributor Author

@cebe, I will try to add unit tests for the week

@valinurovam
Copy link
Contributor Author

Find some bug... all values will be sort like strings. For example we have numeric pk id (1,2,3,4...11,12...21,22). The result for by id will be
1,11,12,...,2,21,22,...3,31,32, but not 1,2,3,4,5...31,32,33.

Don't have any idea to solve this. May be test is_numeric for values and use type casting for numeric values

@valinurovam
Copy link
Contributor Author

Hi all again. Tried to fix all bugs and errors. Remove duplicated test consisted orderBy call.
Can you review it again?

Tell me pls, should I add test for this case:
Customer::find()->andFilterWhere(['id' => [3,4,1]])->orderBy(['id' => SORT_DESC])->indexBy('id')->all();

@@ -369,6 +366,21 @@ protected function executeScript($db, $type, $columnName = null)
*/
private function findByPk($db, $type, $columnName = null)
{
if (!empty($this->orderBy) && in_array($type, ['All', 'One', 'Count', 'Column'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not need sorting for type 'Count'.
And this expression must be assigned to a variable because it's duplicated 2 times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx, fixed

@@ -369,6 +366,22 @@ protected function executeScript($db, $type, $columnName = null)
*/
private function findByPk($db, $type, $columnName = null)
{
$typesForOrder = ['All', 'One', 'Column'];
if (!empty($this->orderBy) && in_array($type, $typesForOrder)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

$needSort = !empty($this->orderBy) && in_array($type, ['All', 'One', 'Column']);
if ($needSort) {
...
}

@valinurovam
Copy link
Contributor Author

Hi all,
Can you review it again?

@valinurovam
Copy link
Contributor Author

Any changes?

@@ -369,6 +366,22 @@ protected function executeScript($db, $type, $columnName = null)
*/
private function findByPk($db, $type, $columnName = null)
{
$needSort = !empty($this->orderBy) && in_array($type, ['All', 'One', 'Column']);
if ($needSort) {
if (count($this->orderBy) > 1)
Copy link
Member

Choose a reason for hiding this comment

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

Need { and } even for one liners.

@alexk984 alexk984 mentioned this pull request Apr 27, 2016
@koxu1996
Copy link

Hey, what about merging it?

@cebe cebe modified the milestones: 2.0.7, 2.0.x Jul 31, 2017
@nnrudakov
Copy link

Excuse me, have repo team plan to merge this pr or something wrong with it?

@cebe cebe closed this in 8c2653d Dec 5, 2017
@cebe
Copy link
Member

cebe commented Dec 5, 2017

Finally found the time to review this, merged, Thank you @valinurovam!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants