如何在 Doctrine2 中添加列描述(注释) [英] How to add column descriptions (comments) in Doctrine2
问题描述
我想向 Doctrine2 实体定义的列添加列描述(也称为评论"),但找不到任何信息关于如何使用 @Column 注释
做到这一点,而不会破坏 Doctrine 的 SchemaTool.
如果我使用 @Column 注释
的 columnDefinition
属性就像
@Column(type=string" columnDefinition=COMMENT '这是一个列注释'")
注释引用 状态
<块引用>如果您使用columnDefinition",SchemaTool 将不再正确检测列上的更改.
那么有没有办法在不破坏 SchemaTool 的情况下定义列描述?
我得到的唯一线索是这个拉取请求,它以这是用不同的方式解决的."
您可以使用注释的options"参数向列名或整个表添加注释;例如:
/*** @ORMColumn(type="string", options={"comment":"下拉列表中显示的字符串"})*/
对于列或表:
/*** @ORM实体* @ORMTable(name="application", options={"comment":"资助申请"});*/
但是请注意,这不会向现有表或列添加注释,您必须从数据库中删除该表并重建它.如果只是添加注释,您可以重命名表,创建新表,然后从原始表中导入数据.
来源:教义文档>
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:
/**
* @ORMColumn(type="string", options={"comment":"The string to show in the dropdown "})
*/
for a column, or for a table:
/**
* @ORMEntity
* @ORMTable(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
这篇关于如何在 Doctrine2 中添加列描述(注释)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!