In Symfony 1.4 and Doctrine 1.2 i can:
$bodies = Doctrine::getTable('Body')->createQuery('b')
->where('b.visible = 1')
->orderBy('LENGTH(b.title) ASC')
->execute();
and then working ok.
In Symfony 2 and Doctrine 2 i have:
$bodies = $this->getDoctrine()
->getRepository('MainBodyBundle:Body')
->createQueryBuilder('b')
->where('b.visible = 1')
->orderBy('LENGTH(b.title)', 'ASC')
->getQuery()
->getResults();
but this not working, i have error:
An exception has been thrown during the rendering of a template ("[Syntax Error] line 0, col 114: Error: Expected end of string, got '('") in "MainBodyBundle::index.html.twig".