qbbr/pgsql-doctrine-random-function

Doctrine ORM 的 PostgreSQL RANDOM() 函数

安装数: 85,714

依赖项: 0

建议者: 0

安全: 0

星星: 4

关注者: 4

分支: 1

开放问题: 1

类型:symfony-bundle

1.0.1 2016-03-12 11:10 UTC

This package is auto-updated.

Last update: 2024-09-14 17:00:57 UTC


README

Doctrine ORM 的 PostgreSQL RANDOM() 函数

Latest Stable Version Total Downloads License

安装

步骤 1: 下载包

$ composer require qbbr/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();