XF 2.0 fetch random results with ->order('rand()')

Marcus

Well-known member
Is there a convenient way randomly fetch an item of the results as ->order('rand()') does not work? Thank you.

Code:
InvalidArgumentException: Unknown column rand(). src/XF/Mvc/Entity/Finder.php:1398
#0 src/XF/Mvc/Entity/Finder.php(523): XF\Mvc\Entity\Finder->resolveFieldToTableAndColumn('rand()', true)
#1 src/XF/Mvc/Entity/Finder.php(852): XF\Mvc\Entity\Finder->columnSqlName('rand()', true)
#2 php(): XF\Mvc\Entity\Finder->order('rand()')
 
If I replace fetchOne() with expression('ORDER BY rand()') the returned object is not an XF object anymore.
 
Back
Top Bottom