top-think / top-think/think-orm
使用hasWhere再使用withCount会导致withCount的别名错误
Open
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 437
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
User::hasWhere('profile',[['true_name','=','thinkphp']])->withCount('article')->xxx
如果再使用了hasWhere后,查询语句默认使用的User作为数据表别名,但withCount中,使用的是$this->parent->getTable()即user作为数据表别名,所有会导致查询时报1054的错误。
如果要修复的话,改动可能比较大,还是官方来改吧
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the query chain using User::hasWhere('profile', ...) followed by withCount('article'), then inspect the hasWhere and withCount entry points for how each assigns the table alias. Confirm the fix by ensuring the generated query no longer raises MySQL error 1054.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100