Doctrine and LIKE query

后端 未结 5 1805
滥情空心
滥情空心 2021-02-06 20:44

I have entity for Doctrine:



        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 21:08

    This is not possible with the magic methods, however you can achieve this using DQL (Doctrine Query Language). In your example, assuming you have entity named Orders with Product property, just go ahead and do the following:

    $dql_query = $em->createQuery("
        SELECT o FROM AcmeCodeBundle:Orders o
        WHERE 
          o.OrderEmail = 'some@mail.com' AND
          o.Product LIKE 'My Products%'
    ");
    $orders = $dql_query->getResult();
    

    Should do exactly what you need.

提交回复
热议问题