json_array type generate unexpected/unwanted column comment: (DC2Type:json_array) #6764

Closed
opened 2026-01-22 15:38:15 +01:00 by admin · 2 comments
Owner

Originally created by @alex-eptb on GitHub (Jun 22, 2021).

Hi,

An unwanted comment '(DC2Type:json_array)' is generated when setting json_array type with annotation.
FYI, if I add my own comment, '(DC2Type:json_array)' is appended to it.

Expected result: no comment.

Way/test to reproduce:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=DummyEntityRepository::class)
*/
class DummyEntity
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string")
     */
     private $myString;

    /**
     * @ORM\Column(type="json_array", options={"jsonb"=true})
     */
     private $myJsonb;
     
    ...
}

Here is the unexpected migration result:

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE SEQUENCE dummy_entity_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql('CREATE TABLE dummy_entity (id INT NOT NULL, my_string VARCHAR(255) NOT NULL, my_jsonb JSONB NOT NULL, PRIMARY KEY(id))');
        $this->addSql('COMMENT ON COLUMN dummy_entity.my_jsonb IS \'(DC2Type:json_array)\'');
    }


Originally created by @alex-eptb on GitHub (Jun 22, 2021). Hi, An unwanted comment '(DC2Type:json_array)' is generated when setting json_array type with annotation. FYI, if I add my own comment, '(DC2Type:json_array)' is appended to it. Expected result: no comment. Way/test to reproduce: ```php <?php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass=DummyEntityRepository::class) */ class DummyEntity { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string") */ private $myString; /** * @ORM\Column(type="json_array", options={"jsonb"=true}) */ private $myJsonb; ... } ``` Here is the unexpected migration result: ```php public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs $this->addSql('CREATE SEQUENCE dummy_entity_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE TABLE dummy_entity (id INT NOT NULL, my_string VARCHAR(255) NOT NULL, my_jsonb JSONB NOT NULL, PRIMARY KEY(id))'); $this->addSql('COMMENT ON COLUMN dummy_entity.my_jsonb IS \'(DC2Type:json_array)\''); }
admin closed this issue 2026-01-22 15:38:15 +01:00
Author
Owner

@beberlei commented on GitHub (Jun 22, 2021):

While you find this comment unwanted, it is necessary to make our Schema Tool work, so this is the expected behavior.

However, maybe you should look into the json DBAL type, which is a more modern version of the deprecated json_array type. It uses the underlying json datatype and should not require the comment to my knowledge. This requires a recent DBAL version such as 2.13

@beberlei commented on GitHub (Jun 22, 2021): While you find this comment unwanted, it is necessary to make our Schema Tool work, so this is the expected behavior. However, maybe you should look into the `json` DBAL type, which is a more modern version of the deprecated `json_array` type. It uses the underlying json datatype and should not require the comment to my knowledge. This requires a recent DBAL version such as 2.13
Author
Owner

@alex-eptb commented on GitHub (Jun 23, 2021):

Really? Storing orm stuff in table comment looks pretty hacky to me. :)
Thanks for this advice anyway. Json type is the correct way.

@alex-eptb commented on GitHub (Jun 23, 2021): Really? Storing orm stuff in table comment looks pretty hacky to me. :) Thanks for this advice anyway. Json type is the correct way.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6764