mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-04 14:22:48 +08:00
修正关联withCount查询
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
namespace think\model\relation;
|
||||
|
||||
use think\Collection;
|
||||
use think\Db;
|
||||
use think\db\Query;
|
||||
use think\Exception;
|
||||
use think\Loader;
|
||||
@@ -338,7 +339,7 @@ class BelongsToMany extends Relation
|
||||
return $this->belongsToManyQuery($this->foreignKey, $this->localKey, [
|
||||
'pivot.' . $this->localKey => [
|
||||
'exp',
|
||||
'=' . $this->parent->getTable() . '.' . $this->parent->getPk(),
|
||||
Db::raw('=' . $this->parent->getTable() . '.' . $this->parent->getPk()),
|
||||
],
|
||||
])->fetchSql()->count();
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ class HasMany extends Relation
|
||||
if ($closure) {
|
||||
call_user_func_array($closure, [ & $this->query]);
|
||||
}
|
||||
$count = $this->query->where([$this->foreignKey => $result->$localKey])->count();
|
||||
$count = $this->query->where($this->foreignKey, $result->$localKey)->count();
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
@@ -160,12 +160,7 @@ class HasMany extends Relation
|
||||
call_user_func_array($closure, [ & $this->query]);
|
||||
}
|
||||
$localKey = $this->localKey ?: $this->parent->getPk();
|
||||
return $this->query->where([
|
||||
$this->foreignKey => [
|
||||
'exp',
|
||||
'=' . $this->parent->getTable() . '.' . $localKey,
|
||||
],
|
||||
])->fetchSql()->count();
|
||||
return $this->query->whereExp($this->foreignKey, '=' . $this->parent->getTable() . '.' . $localKey)->fetchSql()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace think\model\relation;
|
||||
|
||||
use think\Db;
|
||||
use think\db\Query;
|
||||
use think\Exception;
|
||||
use think\Loader;
|
||||
@@ -201,7 +202,7 @@ class MorphMany extends Relation
|
||||
return $this->query->where([
|
||||
$this->morphKey => [
|
||||
'exp',
|
||||
'=' . $this->parent->getTable() . '.' . $this->parent->getPk(),
|
||||
Db::raw('=' . $this->parent->getTable() . '.' . $this->parent->getPk()),
|
||||
],
|
||||
$this->morphType => $this->type,
|
||||
])->fetchSql()->count();
|
||||
|
||||
Reference in New Issue
Block a user