dql

How to select randomly with doctrine

喜夏-厌秋 提交于 2019-11-26 07:43:08
问题 Here is how I query my database for some words $query = $qb->select(\'w\') ->from(\'DbEntities\\Entity\\Word\', \'w\') ->where(\'w.indictionary = 0 AND w.frequency > 3\') ->orderBy(\'w.frequency\', \'DESC\') ->getQuery() ->setMaxResults(100); I\'m using mysql and I\'d like to get random rows that match the criteria, I would use order by rand() in my query. I found this similar question which basically suggests since ORDER BY RAND is not supported in doctrine, you can randomize the primary key