Solution to the problem that TP6 correlation statistics cannot remove duplicates

In the official manual and source code of tp6, there is no way to achieve deduplication and association statistics, because the withCount method in the source code defaults to "*" for statistics. It is very troublesome when we want to count the number of types, not the number of quantities.

 

At this time, you need to modify the source code and change the default "*" to the method of passing parameters. You can use the "distinct filed" method to remove duplicates when calling.

Practical operation:

Find vendor>topthink>think-orm>src>db>concern>ModelRelationQuery.php in the tp6 file

Find the location of the withCount method and modify it as shown in the figure

おすすめ

転載: blog.csdn.net/baidu_36095053/article/details/126997759