The orderBy method should take the Songs field for sorting purposes (for example, 's.author' or 's.title'), and not a random value. Even if you chose a random field for ordering, for example, choosing one random case in php, it will not be very random at all, because you will always get the first result for the current sorting criteria. If your songs have 8 fields, you will only get 8 different songs in the search results, even if you have thousands of saved files.
Here is a suggestion:
$qb1->select('s') ->from('\My\Entity\Song', 's') ->where('s.id <> ?1') ->setMaxResults(1) ->setParameters(array(1=>$current->id)) ->setFirstResult($offset);
Here $ offset may be a random value that you get in php through the rand () or mt_rand () functions. Of course, $ offset should be less than the total number of songs. This is just a suggestion, there are many ways to do this.
IMHO I think Doctrine2 is an unusual ORM, and there is nothing so advanced. I assume that you have read the Query Builder section of the reference manual, but I also suggest you read the DQL , which explains what functions are available in the Doctrine query system, and how you can create your own (!).
faken
source share