PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 10, 2022

[FIXED] How to add column descriptions (comments) in Doctrine2

 January 10, 2022     doctrine-orm, symfony     No comments   

Issue

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


Solution

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



Answered By - ChrisNY
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing