mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
修正hasMany关联的has方法
This commit is contained in:
@@ -147,8 +147,8 @@ class HasMany extends Relation
|
|||||||
return $this->query->where([
|
return $this->query->where([
|
||||||
$this->foreignKey => [
|
$this->foreignKey => [
|
||||||
'exp',
|
'exp',
|
||||||
'=' . $this->parent->getTable() . '.' . $this->parent->getPk()
|
'=' . $this->parent->getTable() . '.' . $this->parent->getPk(),
|
||||||
]
|
],
|
||||||
])->fetchSql()->count();
|
])->fetchSql()->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,13 +217,14 @@ class HasMany extends Relation
|
|||||||
* @param string $operator 比较操作符
|
* @param string $operator 比较操作符
|
||||||
* @param integer $count 个数
|
* @param integer $count 个数
|
||||||
* @param string $id 关联表的统计字段
|
* @param string $id 关联表的统计字段
|
||||||
|
* @param string $joinType JOIN类型
|
||||||
* @return Query
|
* @return Query
|
||||||
*/
|
*/
|
||||||
public function has($operator = '>=', $count = 1, $id = '*')
|
public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER')
|
||||||
{
|
{
|
||||||
$table = $this->query->getTable();
|
$table = $this->query->getTable();
|
||||||
return $this->parent->db()->alias('a')
|
return $this->parent->db()->alias('a')
|
||||||
->join($table . ' b', 'a.' . $this->localKey . '=b.' . $this->foreignKey, $this->joinType)
|
->join($table . ' b', 'a.' . $this->localKey . '=b.' . $this->foreignKey, $joinType)
|
||||||
->group('b.' . $this->foreignKey)
|
->group('b.' . $this->foreignKey)
|
||||||
->having('count(' . $id . ')' . $operator . $count);
|
->having('count(' . $id . ')' . $operator . $count);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user