I use json
column in doctrine 2
(In MySQL
database).
Actually, I made my search in json
with native query like
I was just facing the same problem, but didn't want to install an additional extension. The code snippet from the original question just needs a small enhancement to work:
$rsm = $this->createResultSetMappingBuilder('n');
$rsm->addRootEntityFromClassMetadata(MyObject::class, 'n');
$rawQuery = sprintf('SELECT %s FROM my_objects n WHERE JSON_EXTRACT(current_state, \'$.processing\')', $rsm->generateSelectClause());
$query = $this->_em->createNativeQuery($rawQuery, $rsm);
return $query->getResult();
And it works like a charm.
I solved my problem. I found this extension of DQL .
$queryBuilder = $entityManager->createQueryBuilder();
$query = $queryBuilder
->select("o")
->from(\bla\bla\MyObject::class, "o")
->where("JSON_EXTRACT(o.jsonData, :jsonPath) = :value ")
->setParameter('jsonPath', '$.test.key1')
->setParameter('value', 'value1')
->getQuery();
$co = $query->getResult();