top-think / top-think/think-orm

使用hasWhere再使用withCount会导致withCount的别名错误

Open
#202 1 comment 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.