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

[7.x] New method withSum for sum one or more columns for the relations #32474

Closed
wants to merge 4 commits into from
Closed

Conversation

Alexmg86
Copy link

Added new method withSum for sum one or more columns for the relations without second sql query.

It's working like withCount. Three type:

  1. Invoice::withSum('items:price,price2')->first(); where price, price2 are columns
  2. $invoices = Invoice::first(); $invoices->loadSum('items:price');
  3. $invoices = Invoice::withSum(['items:price,price2' => function (Builder $query) {
    $query->where('id','<', 30);
    }])->get();

I often use this in my work and I hope it will be useful to you!

…s without second sql query.

It's working like withCount. Three type:
1) Invoice::withSum('items:price,price2')->first(); where price,price2 are columns
2) $invoices = Invoice::first(); $invoices->loadSum('items:price');
3) $invoices = Invoice::withSum(['items:price,price2' => function (Builder $query) {
	  $query->where('id','<', 30);
   }])->get();

I often use this in my work and I hope it will be useful to you!
@driesvints driesvints changed the title New method withSum for sum one or more columns for the relations [7.x]New method withSum for sum one or more columns for the relations Apr 21, 2020
@driesvints driesvints changed the title [7.x]New method withSum for sum one or more columns for the relations [7.x] New method withSum for sum one or more columns for the relations Apr 21, 2020
@taylorotwell
Copy link
Member

I am closing this pull request because it lacks sufficient explanation, tests, or both. It is difficult for us to merge pull requests without these things because the change may introduce breaking changes to the framework.

Feel free to re-submit your change with a thorough explanation of the feature and tests - integration tests are preferred over unit tests. Please include it's benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.

Thanks!

@khalilst
Copy link
Contributor

khalilst commented Nov 3, 2020

@Alexmg86
I am really sorry your PR rejected here. However, I think it should be because it not DRY at all.
You have just copy and pasted the withCount method and its relatives to add withSum and nothing else.
You claimed here #34965 that I have stolen your code from this PR and your package with your insulting words.
The PRs are not similar at all, they are not even close together.
Your package also https://github.com/Alexmg86/laravel-sub-query
has main differences with my PR (codes-style, naming, method signatures & ...)
But assume if I copied from your unknown package, why I copied only some parts and not everything from there e.g. withMath from yours?!
And in addition to you should know the exact meaning of open-source, apparently you do not!
I have never seen your poor codes before and I know you are upset that your PR rejected and your package is useless now.
But you have to be polite and try harder to become a good programmer. Your are far away from both and this is the main reason that your are upset now.

@driesvints
Copy link
Member

@khalilst I closed that other PR for a reason. Please stop bringing this up.

@laravel laravel locked and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants