Skip to content

[5.4] If there is a withCount, Than also is withSum/withAvg/withMin/withMax #18303

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

Closed
wants to merge 6 commits into from

Conversation

xuqihua
Copy link

@xuqihua xuqihua commented Mar 11, 2017

No description provided.

@GrahamCampbell GrahamCampbell changed the title If there is a withCount, Than also is withSum/withAvg/withMin/withMax [5.4] If there is a withCount, Than also is withSum/withAvg/withMin/withMax Mar 11, 2017
@fernandobandeira
Copy link
Contributor

fernandobandeira commented Mar 12, 2017

This is actually a breaking change for the withCount method, when no column is passed to withCount it should use * and not id also I don't think it's good to hard code id there, maybe you could try getting the primary key of the model?

This is breaking because count(column) will not count when the column is null, also ppl may be using this on a model that doesn't have the id column...

Also this is missing tests, but it's a nice feature would like to see it into the framework 😄.

Old PR #16815

@xuqihua
Copy link
Author

xuqihua commented Mar 13, 2017

@fernandobandeira
Thank you. I dont know there is old PR.
I have tested it in my project 😂

public function getRelationExistenceAggregateQuery(Builder $query, Builder $parentQuery, $type, $column)
{
return $this->getRelationExistenceQuery(
$query, $parentQuery, new Expression("$type($column)")
Copy link
Contributor

@fernandobandeira fernandobandeira Mar 13, 2017

Choose a reason for hiding this comment

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

We actually should wrap the column name here:

Expression($type.'('.$this->query->getGrammar()->wrap($column).')')

The rest seems fine now 👍

@taylorotwell
Copy link
Member

If this is a breaking change we can not merge it into 5.4.

@Numline1
Copy link

@taylorotwell Any chance this would make it into 5.5? What changes would be necessary, except the stated defaults (PK or * instead of "id")?

@decadence
Copy link
Contributor

@xuqihua can you make it for 5.5?

@xuqihua
Copy link
Author

xuqihua commented May 27, 2017

@decadence
Maybe, but I have used another way to solve such situation。
sub-query is a slow solution

@decadence
Copy link
Contributor

@xuqihua
Yes but sometimes it's acceptable.
Give it a try for 5.5 please.

@xuqihua
Copy link
Author

xuqihua commented May 27, 2017

@decadence
okay

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.

5 participants