有没有办法按 Title
字段中包含的字符串长度订购此查询?
$query = $this->getEntityManager()
->createQuery('
SELECT b FROM AcmeTestBundle:Blog b
WHERE b.Title LIKE :title'
)->setParameter('title','%'.$title.'%');
ORDER BY b.Title.length()
似乎不起作用。
答案 0 :(得分:5)
是的,试试吧:
$query = $this->getEntityManager()->createQuery('SELECT LENGTH(b.Title) l, b FROM AcmeTestBundle:Blog b WHERE b.Title LIKE :title ORDER BY l')->setParameter('title','%'.$title.'%');