-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[10.x] Fix CanBeOneOfMany
giving erroneous results
#47427
Conversation
CanBeOneOfMany
giving erroneous results
Is there anything wrong with my PR preventing it to be merged ? |
@Guilhem-DELAITRE just think Taylor hasn't gotten to this one yet with all the pre and post Laracon US stuff. |
@driesvints |
if ($key === 0) { | ||
$aggregatedColumn = "{$aggregate}({$aggregatedColumn})"; | ||
} else { | ||
$aggregatedColumn = "min({$aggregatedColumn})"; |
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.
Why min
here? Can you explain the entire logic behind this PR and how it fixes the issue?
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.
The min
purpose is to use an aggregate to select any value on a column which we already know all value are the same because it's the sub-level aggregate. We still need an aggregate because there's no group by
clause on that column. The most correct solution would probably be to add a group by on that column, but I didn't manage to do it in the time I had.
The more global purpose of the PR is fully stated and detailed (and is demonstrated by the modification of the generated query) in the original PR : #46309
The last two commits purpose is to fix the problem mentionned in
#46394 which was due to my modification not working with DBRMS which are strict with aggregates / group by like PostgreSQL.
This PR shouldn't be called "Fix" as it introduced new usage from Currentreturn $this->hasOne(Profle::class)->ofMany('created_at', 'max'); Afterreturn $this->hasOne(Profle::class)->ofMany([
'created_at', 'max',
'updated_at', 'max',
]); Also I believe a similar tests should be added using |
@crynobone BUT this usage (using multiple aggregate in You are right about the part |
Regardless, this need Integration tests |
@crynobone Seems that they passed successfully. |
* Add test to pinpoint the dysfunction * FIX CanBeOneOfMany.php * FIX test on raw sql * FIX missing aggregate for strict RDBMS (like postgresql) * FIX * Add integration test to ensure multi-databases coverage * Update EloquentHasOneOfManyTest.php * Update EloquentHasOneOfManyTest.php * wip * wip * wip * wip * wip --------- Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>
This PR topic and content is identical to #46309 except I added a fix for strict RDBMS (like PostgreSQL) which doesn't support approximate usage of aggregate / group by.