Query with field of type json in Doctrine 2 and Symfony 3

0

Does anyone know a way to perform a query using Doctrine which has a JSON field?

Postgresql query example:

select id, nome, tipo, '{"idUsuario":465,"login":"paulo"}'::json
from public.usuarios
limit 5;

I need to make this query in Doctrine 2, does anyone know how?

    
asked by anonymous 08.04.2016 / 21:43

1 answer

0

This depends somewhat on how your system is modeled. Are you using EntityManager to map your classes to tables, or not?

If so, there is a bundle that solves this: link . You say that property is type jsonb and it does the queries the way the bundle instructs you.

If you are using DBAL, this is already supported, as you can see in the Doctrine mapping table: link

Finally, if none of the solutions above help, you can still use the createNativeQuery function to perform a native function of that particular database and have an array of results as a return.

    
11.05.2016 / 09:21