top-think / top-think/think-orm

withJoin生成SQL不带前缀

Open
#551 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

THINKPHP 6.0.3

Order::withJoin([
'userInfo' => ['id', 'nick_name'],
'currency' => ['iname', 'an', 'pn', 'vn']
], 'LEFT')
->withCount(['subOrderCount' => function ($query, &$alias) {
$query->where('status', 'IN', '0,1,6');
$alias = 'sub_total';
}])
->withCount(['subOrderCount' => function ($query, &$alias) {
$query->where('status', 'IN', '3,4,7');
$alias = 'sub_cancel_total';
}])
->where($where)
->limit($pagetion['offsize'], $pagetion['limit'])
->order($pagetion['order'])
->select()
->toArray();

DB配置数据表前缀后, 执行以上语句生成SQL,字段部分不带前缀,数据库报错,withJoin方法生成语句没有自动增加表前缀

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 by reproducing the provided Think ORM 6.0.3 example with a configured table prefix, then trace the withJoin SQL generation path. The issue is done when the generated SQL prefixes the selected fields correctly and executes without the reported database error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.