Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add column descriptions (comments) in Doctrine2

I would like to add a column description (also called a "comment") to a column defined by a Doctrine2 entity but can't find any information on how to do it using the @Column annotation without possibly breaking Doctrine's SchemaTool.

If I use the columnDefinition attribute of the @Column annotation like

@Column(type="string" columnDefinition="COMMENT 'This is a column comment'")

the annotations reference states

SchemaTool will not detect changes on the column correctly anymore if you use “columnDefinition”.

So is there a way to define a column description without breaking the SchemaTool?

The only clue I got was this pull request which ended in "This was solved in different ways.".

like image 532
flu Avatar asked Aug 13 '12 11:08

flu


1 Answers

You can add a comment to a column name or entire table with the "options" argument to the annotation; eg:

/**
 * @ORM\Column(type="string", options={"comment":"The string to show in the dropdown "})
 */

for a column, or for a table:

/**
 * @ORM\Entity
 * @ORM\Table(name="application", options={"comment":"Funding applications"});
 */

Note however this will not add comments to an existing table or column, you have to delete the table from the DB and rebuild it. If it's just adding comments, you could rename the table, create the new table, and import data from the original.

Source: Doctrine documentation

like image 82
ChrisNY Avatar answered Nov 09 '22 07:11

ChrisNY