title: Symfony find user by role (JSON array Doctrine property)
body: <p>I am doing a small project where I have an entity with a roles property which consists of an array.</p>
  <p>What I am trying to do is, in some controller, find an existing entity which has a specific role inside of the roles array.</p>
  <p>I am trying to use the <code>findOneBy()</code> method, but I can't seem to make it work, it always returns null even though entities with the specific role I'm trying to find exist.</p>
  <p>Here is my entity and its properties:</p>
  <pre class="lang-php prettyprint-override"><code>/**
   * @ORM\Entity(repositoryClass=SalarieRepository::class)
   */
  class Salarie
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $nom;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $prenom;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $email;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $telephone;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $service;
  
      /**
       * @ORM\Column(type=&quot;json&quot;)
       */
      private $roles = [];
  
      // Getters &amp; setters
  }
  </code></pre>
  <p>And here is an example of something I tried with <code>findOneBy()</code> inside a controller, that returns <code>null</code>:</p>
  <pre><code>$rolecheck = $this-&gt;salarieRepository-&gt;findOneBy([&quot;roles&quot; =&gt; [&quot;ROLE_RESPONSABLE_RH&quot;]]);
  </code></pre>
  <p>When I try with any other property of the entity which isn't an array it works well, if I do something like this:</p>
  <pre><code>$rolecheck = $this-&gt;salarieRepository-&gt;findOneBy([&quot;nom&quot; =&gt; &quot;test&quot;]);
  dd($rolecheck);
  </code></pre>
  <p>It will show the right entity :</p>
  <pre><code>SalarieController.php on line 47:
  App\Entity\Salarie {#1501 ▼
    -id: 6
    -nom: &quot;test&quot;
    -prenom: &quot;test&quot;
    -email: &quot;test@test.test&quot;
    -telephone: null
    -service: &quot;Graphisme&quot;
    -roles: array:3 [▼
      0 =&gt; &quot;ROLE_RESPONSABLE_RH&quot;
      1 =&gt; &quot;ROLE_RESPONSABLE_SERVICE&quot;
      2 =&gt; &quot;ROLE_SALARIE&quot;
    ]
  }
  </code></pre>
  <p>Where we can also see it does have the roles array with the role I'm trying to find inside it.</p>
  <p>Any clues on how I could try to find one entity which has the specific role <code>&quot;ROLE_RESPONSABLE_RH&quot;</code>?</p>