MySql Doctrine: find if given variable is IN array property

后端 未结 1 1874
死守一世寂寞
死守一世寂寞 2021-01-07 01:28

I have class Task with categories array of integers property

class Task{
      /**
       * @var array
       *
       * @ORM\\Column(name=\"cat         


        
相关标签:
1条回答
  • 2021-01-07 02:13

    To the best of my knowledge this isn't possible in Doctrine directly as the array isn't technically an array until it has been unserialized from the database.

    The only way I know to get the result you are looking for is to treat your database value as a string and search for the required string in that value using a like with wildcards.

    $qb = $this->getDoctrine()->getRepository('CoreBundle:Task')->createQueryBuilder('t');
    $qb->where('t.categories LIKE :category')
       ->setParameter('category', '%'.$category.'%');
    
    0 讨论(0)
提交回复
热议问题