【问题标题】:Symfony Doctrine 预期的已知函数,得到 'JSON_GET_TEXT'
【发布时间】:2022-01-21 01:44:45
【问题描述】:

我正在尝试使用DoctrineJsonFunctions 过滤用户表的角色列。

我已按照文档搜索并寻求帮助,但找不到解决问题的方法。

我已经正确安装了DoctrineJsonFunctions

我在UserRepository 中创建了一个函数

public function findByRole(string $role)
    {
        $em = $this->getEntityManager();
        $qb = $em->createQueryBuilder();

        $qb
            ->select('u')
            ->from('App:User', 'u')
            ->where("JSON_GET_TEXT(user.roles, 'role') = :role")
            ->setParameter('role', $role)
            ->getQuery()
            ->getResult();
    }

但我遇到了这个错误:

预期的已知函数,得到'JSON_GET_TEXT'

有没有人知道为什么并且可以帮助我解决它?

【问题讨论】:

    标签: php symfony doctrine-orm doctrine


    【解决方案1】:

    终于找到了错误的原因。 我必须在 dql 下的教义.yaml 文件中添加以下内容:

    JSON_GET_TEXT: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Postgresql\JsonGetText
    

    继续,这是我的学说.yaml 文件:

    doctrine:
        dbal:
            url: '%env(resolve:DATABASE_URL)%'
    
            # IMPORTANT: You MUST configure your server version,
            # either here or in the DATABASE_URL env var (see .env file)
            #server_version: '13'
        orm:
            auto_generate_proxy_classes: true
            naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            auto_mapping: true
            mappings:
                App:
                    is_bundle: false
                    type: annotation
                    dir: '%kernel.project_dir%/src/Entity'
                    prefix: 'App\Entity'
                    alias: App
            dql:
                string_functions:
                    JSON_EXTRACT: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql\JsonExtract
                    JSON_SEARCH: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql\JsonSearch
                    JSON_GET_TEXT: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Postgresql\JsonGetText
    

    【讨论】:

      猜你喜欢
      • 2016-02-18
      • 2020-01-25
      • 1970-01-01
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      • 2013-12-26
      • 2011-05-18
      相关资源
      最近更新 更多