top-think / top-think/think-orm

在配置有多个数据库的情况下,model::withCount不能生成正确的sql语句

Open
#291 0 comments 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

在配置有多个数据库的情况下,model::withCount不能生成正确的sql语句,如下

SELECT COUNT(*) AS think_count FROM `xxx_table` `count_table` WHERE (  ( `count_table`.`xxx_field` =xxx ) ) AND `count_table`.`delete_time` = '0'

生成的sql语句不会带上相应的连接信息导致PDO报错。

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

Start at model::withCount and reproduce the query with multiple databases configured. Inspect how the count query chooses its connection, then verify that the generated SQL uses the corresponding connection and no longer causes a PDO error. The issue names no source file or test, so locating the relevant implementation and regression coverage is part of the work.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.