aldaflux/pgsql-doctrine-random-function

Doctrine ORM 的 PostgreSQL RANDOM() 函数,基于 https://packagist.org.cn/packages/qbbr/pgsql-doctrine-random-function 的分支

安装: 3

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 1

类型:symfony-bundle

dev-master 2024-08-16 16:53 UTC

This package is auto-updated.

Last update: 2024-09-16 16:56:20 UTC


README

Doctrine ORM 的 PostgreSQL RANDOM() 函数

Latest Stable Version Total Downloads License

安装步骤

步骤 1: 下载软件包

$ composer require aldaflux/pgsql-doctrine-random-function

步骤 2: 配置

# app/config/config.yml

doctrine:
    orm:
        # ...
        dql:
            numeric_functions:
                Random: Qbbr\PgsqlDoctrineRandomFunction\DQL\RandomFunction

使用方法

$em = $this->getDoctrine()->getManager();

$result = $em->createQueryBuilder()
    ->select('e')
    ->from('AppBundle:Entity', 'e')
    ->orderBy('RANDOM()')
    ->setMaxResults(10)
    ->getQuery()
    ->getResult();