如何在Doctrine2中添加列描述(注释) [英] How to add column descriptions (comments) in Doctrine2

查看:335
本文介绍了如何在Doctrine2中添加列描述(注释)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个列描述(也称为注释)添加到由Doctrine2实体定义的列中,但是找不到有关如何要使用 @Column注释,而不会破坏Doctrine的SchemaTool。

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.

如果我使用 columnDefinition 属性 @Column注释

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

注释引用状态


如果您使用columnDefinition,SchemaTool将无法正确检测列的更改。

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

那么有没有办法定义一个列描述,而不会破坏SchemaTool?

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 "})
 */

一列或一张表:

/**
 * @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.

资料来源:原则文件

这篇关于如何在Doctrine2中添加列描述(注释)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆