background preloader

Symfony

Facebook Twitter

Symfony 2: Doctrine 2 get random entites (MySQL) - Custom Web Development Blog. Often during the process of developing projects on the Symfony 2 framework and Doctrine 2 ORM many web applications developers face the problem of getting random records from a MySQL database. Most developers know that this issue is not new, and all solutions that already exist have been known for a long time.

But you can hardly find an implementation of any of them on the Symfony 2 framework and Doctrine 2 in the Internet. In this post I want to propose you , in my opinion, the most simple way of selecting random records from MySQL by means of the function RAND. Attention! This method is not productive. Describe RAND() function As ORM Doctrine 2 does not have support for RAND() function in MySQL, you must describe this function firstly. Then you need to connect this description to the list of functions Doctrine 2 ORM.

. … doctrine: orm: dql: numeric_functions: Rand: Acme\DemoBundle\DQL\RandFunction … Creation of the repository and method for getting random records <? Conclusion.

Errors

Egeloen/IvoryCKEditorBundle.