!5 修正一对多关联的withCount自关联问题

Merge pull request !5 from 筱洛洛/master
This commit is contained in:
Karson
2024-03-26 09:04:03 +00:00
committed by Gitee

View File

@@ -164,7 +164,7 @@ class HasMany extends Relation
}
}
$localKey = $this->localKey ?: $this->parent->getPk();
return $this->query->whereExp($this->foreignKey, '=' . $this->parent->getTable() . '.' . $localKey)->fetchSql()->count();
return $this->query->alias( 'count_table')->whereExp( 'count_table.' . $this->foreignKey, '=' . $this->parent->getTable() . '.' . $localKey)->fetchSql()->count();
}
/**