qbbr/pgsql-doctrine-random-function

PostgreSQL RANDOM() function for Doctrine ORM
117,641 4
Install
composer require qbbr/pgsql-doctrine-random-function
Latest Version:1.0.1
License:MIT
Last Updated:Aug 16, 2024
Links: GitHub  ·  Packagist
Maintainer: qbbr

PgsqlDoctrineRandomFunction

PostgreSQL RANDOM() function for Doctrine ORM

Latest Stable Version Total Downloads License

Installation

Step 1: Download the package

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

Step 2: Configuration

# app/config/config.yml

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

Usage

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

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