top-think / top-think/think-orm

TP6 withCount

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

withCount 方法默认如下
public function withCount($relation, bool $subQuery = true)
{
return $this->withAggregate($relation, 'count', '*', $subQuery);
}

count字段默认是field是* 而且用户没法修改 希望可以修改为
public function withCount($relation, $field = '*', bool $subQuery = true)
{
return $this->withAggregate($relation, 'count', $field, $subQuery);
}
这样用户就可以查询不重复的数据 withCount('list','distinct uid')

文件所在位置 topthink/think-orm/src/db/concern/ModelRelationQuery.php 329行

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

Read topthink/think-orm/src/db/concern/ModelRelationQuery.php around line 329, then follow how withCount delegates to withAggregate. Confirm how the count field is passed through and how a caller could request a distinct uid count. Done means withCount still defaults to * while accepting the requested field without breaking existing calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.