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.".
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With