I'm trying to figure out how, in a symfony 3.4 app, to retrieve (through a repository method, with a DQL request for example) entities depending on a value for a specific key in a "json" typed column. Saw there's some stuff possible with postgre but I didnt find anything with mariaDB
Let's say I get an entity Letter
with this property :
/**
*
* @ORM\Column(type="json")
*/
private $metadatas;
which contains, for example:
{
"key1": "value",
"key2": "value"
}
How can I, or, Is it possible to request my DB to get letters with a specific value for a specific key in metadatas column.
Something like that :
public function getByKeyValue($key, $value)
{
$em = $this->_em;
$dql = "SELECT l FROM AppBundle:Letter l
WHERE l.metadatas->:key = :value
";
$query = $em->createQuery($dql);
$query->setParameter('key', $key);
$query->setParameter('value', $value);
return $query->getResult();
}
some infos :
php7.1, mariadb 10.2+, doctrine/dbal ^2.6, doctrine orm ^2.5
Thanks a lot.
scienta/doctrine-json-functions
, and the namespace was changed. Before it was calledsyslogic/doctrine-json-functions
. – Adversative