Symfony Doctrine 预期已知函数,得到“JSON_GET_TEXT”

Pax*_*Pax 1 php doctrine symfony doctrine-orm

我正在尝试使用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();
    }
Run Code Online (Sandbox Code Playgroud)

但我遇到了这个错误:

预期的已知函数,得到“JSON_GET_TEXT”

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

Pax*_*Pax 5

最后我找到了错误的原因。我必须在 dql 下的doctrine.yaml 文件中添加以下内容:

JSON_GET_TEXT: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Postgresql\JsonGetText
Run Code Online (Sandbox Code Playgroud)

继续,这是我的doctrine.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
Run Code Online (Sandbox Code Playgroud)