doctrine query bulder jsonb result not decoded to an array

18 Views Asked by At

I have a Postgres table like

CREATE TABLE catalog.products (
  id UUID primary key,
  name TEXT,
  tags jsonb[] NOT NULL,
  created_at timestamp default current_timestamp,
  updated_at timestamp default current_timestamp
);

where each tag is json like {"id":"some id", "name":"some name"}, so if in table tags stored like this:

{"{\"id\": \"fbe5aead-3870-428d-b744-5ffd907be5a8\", \"label\": \"Against\"}","{\"id\": \"fbe5aead-3870-428d-b744-5ffd907be5a8\", \"label\": \"Against\"}","{\"id\": \"fbe5aead-3870-428d-b744-5ffd907be5a8\", \"label\": \"Against\"}"}

and later if I'm trying to get products

$productsData =  $this->connection
            ->createQueryBuilder()
            ->from('catalog.products')
            ->select('*')
            ->setFirstResult($from)
            ->setMaxResults($to)
            ->orderBy('id', 'ASC')
            ->executeQuery()
            ->fetchAllAssociative();

tags returned as a string and can't be decoded because format is invalid json

{"{\"id\": \"fbe5aead-3870-428d-b744-5ffd907be5a8\", \"label\": \"Against\"}","{\"id\": \"fbe5aead-3870-428d-b744-5ffd907be5a8\", \"label\": \"Against\"}","{\"id\": \"fbe5aead-3870-428d-b744-5ffd907be5a8\", \"label\": \"Against\"}"}
0

There are 0 best solutions below