mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-10 00:22:48 +08:00
改进hasMany关联
This commit is contained in:
@@ -239,9 +239,14 @@ class HasMany extends Relation
|
|||||||
public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER')
|
public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER')
|
||||||
{
|
{
|
||||||
$table = $this->query->getTable();
|
$table = $this->query->getTable();
|
||||||
return $this->parent->db()->alias('a')
|
$model = basename(str_replace('\\', '/', get_class($this->parent)));
|
||||||
->join($table . ' b', 'a.' . $this->localKey . '=b.' . $this->foreignKey, $joinType)
|
$relation = basename(str_replace('\\', '/', $this->model));
|
||||||
->group('b.' . $this->foreignKey)
|
|
||||||
|
return $this->parent->db()
|
||||||
|
->alias($model)
|
||||||
|
->field($model . '.*')
|
||||||
|
->join($table . ' ' . $relation, $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey, $joinType)
|
||||||
|
->group($relation . '.' . $this->foreignKey)
|
||||||
->having('count(' . $id . ')' . $operator . $count);
|
->having('count(' . $id . ')' . $operator . $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user