How to add column descriptions (comments) in Doctrine2

SymfonyDoctrine Orm

Symfony Problem Overview


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.".

Symfony Solutions


Solution 1 - Symfony

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfluView Question on Stackoverflow
Solution 1 - SymfonyChrisNYView Answer on Stackoverflow