think\Model::has PHP Méthode

has() public static méthode

根据关联条件查询当前模型
public static has ( string $relation, string $operator = '>=', integer $count = 1, string $id = '*' ) : Model
$relation string 关联方法名
$operator string 比较操作符
$count integer 个数
$id string 关联表的统计字段
Résultat Model
    public static function has($relation, $operator = '>=', $count = 1, $id = '*')
    {
        $model = new static();
        $info = $model->{$relation}()->getRelationInfo();
        $table = $info['model']::getTable();
        switch ($info['type']) {
            case Relation::HAS_MANY:
                return $model->db()->alias('a')->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType'])->group('b.' . $info['foreignKey'])->having('count(' . $id . ')' . $operator . $count);
            case Relation::HAS_MANY_THROUGH:
                // TODO
            // TODO
            default:
                return $model;
        }
    }