framework icon indicating copy to clipboard operation
framework copied to clipboard

关联统计-一对多关联(hasMany)存在指定外键不生效的问题,导致统计结果不正确thinkphp5.0.10

Open xsdhy opened this issue 9 years ago • 0 comments

版本:thinkphp5.0.10 描述:关联统计-一对多关联(hasMany)存在指定外键不生效的问题,导致统计结果不正确 解决方案:

在文件:thinkphp/library/think/model/relation/HasMany.php 166行 也就是getRelationCountQuery方法中

原语句:'=' . $this->parent->getTable() . '.' . $this->parent->getPk(), 调整后语句:'=' . $this->parent->getTable() . '.' . ($this->localKey?$this->localKey:$this->parent->getPk()),

调整后,在关联中指定localKey,则使用localKey,否则使用主键。

xsdhy avatar Aug 24 '17 04:08 xsdhy