wszystko ładnie pięknie

jak pobrać 4 losowe rekordy z bazy?
przewertowałem google ale wszędzie jakieś niejasności ,,,
$rand = $em->getRepository('ArticleBundle:Article')->findBy( 4 );
prosze o pomoc
$q = $this->getDoctrine() ->getRepository('ArticleBundle:Article') ->createQueryBuilder('a') ->setMaxResults(4) //->orderBy('RAND()') ->getQuery(); $rand = $q->execute();
$rsm = new ResultSetMapping(); $query = $this->em->createNativeQuery('SELECT * FROM article ORDER BY RAND()', $rsm); $rand = $query->getResult();
<?php namespace My\ArticleBundle\Entity; /** * RandFunction ::= "RAND" "(" ")" */ { public function parse(\Doctrine\ORM\Query\Parser $parser) { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $parser->match(Lexer::T_CLOSE_PARENTHESIS); } public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { return 'RAND()'; } }
$config = new \Doctrine\ORM\Configuration(); $config->addCustomNumericFunction('RAND', 'My\ArticleBundle\Entity\Rand'); $q = $this->getDoctrine() ->getRepository('MyArticleBundle:Article') ->createQueryBuilder('a') ->setMaxResults(4) ->orderBy('RAND()') ->getQuery(); $rand = $q->execute();