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

When relation is morphMany, withCount would cause where bindings mistake #26635

Closed
mitoop opened this issue Nov 27, 2018 · 3 comments
Closed

Comments

@mitoop
Copy link
Contributor

mitoop commented Nov 27, 2018

  • Laravel Version: 5.7.13
  • PHP Version: 7.2.11
  • Database Driver & Version: Mysql 8.0.12

Description:

When use withCount under the relation morphMany and when withCount method call before select method, It will lead that the where bindings will make a mistake.

Steps To Reproduce:

ModelA::withCount('relation')->where(''user_id", 12)->select(['fields'])->get() or paginate().

It will cause where bindings make a mistake. And when select method call before the withCount method, It will be OK. Like this :

ModelA::select(['fields'])->withCount('relation')->where(''user_id", 12)->get() or paginate().

@mitoop mitoop closed this as completed Nov 27, 2018
@mitoop mitoop changed the title withCount where bindings mistake when relation is morphMany. When relation is morphMany, withCount would cause where bindings mistake Nov 27, 2018
@mitoop mitoop reopened this Nov 27, 2018
@driesvints
Copy link
Member

Looks like the same as #26623?

@staudenmeir
Copy link
Contributor

You always have to call withCount() after select().

See #24797 and laravel/docs#4404.

@driesvints
Copy link
Member

@staudenmeir thanks for making me aware. I'll try to resend that docs PR with better wording.

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

No branches or pull requests

3 participants