Doctrine can automatically serialize simple PHP array values (see https://doctrine-orm.readthedocs.io/projects/doctrine-dbal/en/latest/reference/types.html#array-types).
Example
<?php
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="my_table")
*/
class MyTable {
/**
* @var array
*
* @ORM\Column(name="myArray", type="json", nullable=true)
*/
private $myArray;
}
Example in database
| my_array |
|---------------|
|'["FOO","BAR"]'|
Question
Is there a way to query these values without some sort of ugly regex directly by DQL or with query builder?
$queryBuilder
->andWhere(":searchParam IN myTable.myArray")
->setParameter('searchParam', 'FOO');
Side note: I could always wrap the searchParam
and search with LIKE
key word. However I am looking for an alternative solution.