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

参照98af9cd4f6修改的,治标不治本,但是能用
This commit is contained in:
bazhe
2024-03-06 18:25:47 +08:00
parent 8fa1957eb1
commit dcc1ac2bb4

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();
}
/**