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

[5.1] Fix sum with no results #18685

Merged
merged 1 commit into from
Apr 6, 2017
Merged

[5.1] Fix sum with no results #18685

merged 1 commit into from
Apr 6, 2017

Conversation

KnightVision90
Copy link

For ticket #14793, this code was removed to use the numericAggregate function. When it was reverted on ticket #14994 it only replaced sum with returning aggregate even though prior to the initial change this code checked result and returned 0 in case the result was null.

This is just reverting back to how the code was prior to being changed to use numericAggregate so that it will return 0 if there is no results returned.

return $this->aggregate(__FUNCTION__, [$column]);
$result = $this->aggregate(__FUNCTION__, [$column]);

return $result ?: 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not this:

return $this->aggregate(__FUNCTION__, [$column]) ?: 0;

Copy link
Author

Choose a reason for hiding this comment

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

This was just done to revert it back to its original state before the reverted code was applied. If Taylor wants, I can do it like this.

@taylorotwell taylorotwell merged commit 4c909d6 into laravel:5.1 Apr 6, 2017
@GrahamCampbell GrahamCampbell changed the title Fix sum with no results [5.1] Fix sum with no results Apr 7, 2017
@GrahamCampbell
Copy link
Member

👎 This breaks more people's code than it fixes.

@KnightVision90
Copy link
Author

KnightVision90 commented Apr 7, 2017

The merge and revert done caused the functionality of the sum method to change from how it had been for over a year and provided no better functionality and I'd argue a return of null ONLY when there is no sql results wouldn't make sense as it's clear by using the sum() method you are looking for a numeric response.

Can you provide some sources for people's code who are reporting this breaking?

@KnightVision90 KnightVision90 deleted the revert-sum-to-return-zero branch April 7, 2017 18:16
taylorotwell added a commit that referenced this pull request Apr 7, 2017
taylorotwell added a commit that referenced this pull request Apr 7, 2017
@taylorotwell
Copy link
Member

Honestly just think I will revert this. 5.1 is end of life in 2 months and I don't want to change existing functionality at this point. Even if it is unintuitive.

@GrahamCampbell
Copy link
Member

This change was already made in a later laravel version anyway, because it was breaking.

@KnightVision90
Copy link
Author

I'm not seeing any pull requests that mention moving from null to 0 broke their code and this code will match all future versions as well. '0', 0, and null are all false values so if ($val) { will continue to evaluate the same with this code but when you use the value in a blade template, it won't return any string when you are expecting it to return 0. I'm not seeing any references to it being broken before, just that it wasn't returning an integer type rather than a string for all results.

I see this exact request was done and merged in #15345, showing the previous requests broke it for more people than this PR would have. Isn't part of the purpose of LTS to be so that we know how long we can stay on a minor version before we should upgrade? We were waiting until 5.5 LTS to update minor versions and having to do that to fix a bug that was introduced due to a piece of code being missed from a revert seems counter-intuitive.

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

Successfully merging this pull request may close these issues.

4 participants