-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
issue with withCount method #21464
Comments
Please share enough steps of reproduction, how can I reproduce this faulty query using Eloquent code? |
@themsaid Hi, the steps to reproduce is very clear in that post, basically need to have 3 models, first model has many second model, second model has many third model. Second model have protected property $withCount of third model. Third model have a global scope. Using first model Model::withCount method with a function have where query will cause the problem. You can reproduce the error easily just using the code in that post. Sorry about the format, I'm typing from mobile. If something is not clear I can post a more detailed are by step post later on my computer |
Check #21468 |
i think that doesn't fix fully, I opened another issue #21472 for more explanation |
Description:
There is an issue with
withCount
since it re-assign Query Buildercolumns
property byselect()
but didn't clean select bindings, it cause the final SQL binding mismatch.Steps To Reproduce:
This issue is originally found in here
As a note:
select "bookings".*, (select count(*) from "extras" where "bookings"."id" = "extras"."booking_id" and "app_id" = ?) as "extras_count" from "bookings"
, and after that, this same builder instance changed toselect count(*) as "booking_count" from "bookings"
but binding is kept.[1,"open"]
but it only have one?
in SQL, so it replace at wrong place.Fix
See #21465
Extra
during the debugging, i found
getRelationExistenceCountQuery()
andgetRelationExistenceQuery()
inIlluminate\Database\Eloquent\Relations\Relation
class are not using$parentQuery
any more, should we remove this parameter in 5.6?The text was updated successfully, but these errors were encountered: