【问题标题】:Symfony2 store database schema information in database tablesSymfony2 将数据库模式信息存储在数据库表中
【发布时间】:2013-10-18 16:53:44
【问题描述】:

我需要将我的数据库架构信息存储在数据库中。 我已经有一个名为 db_entity 的表,它存储实体名称、命名空间和其他选项。 与此表相关,我需要一个表 entity_attributes,其中包含 entity_id、attribute_name、attribute_type、required 等。

创建模式结构很容易,但是将我所有实体中的所有字段插入数据库中将是一项繁琐的工作。 有什么方法可以创建一个脚本来解析我的所有实体注释,从而允许我将所有字段创建到我的数据库表中?

最好的方法是编写一个与学说:schema:update 类似的命令来更新我的表架构。

谢谢。

【问题讨论】:

    标签: symfony reflection doctrine-orm schema


    【解决方案1】:

    原则元数据类http://www.doctrine-project.org/api/orm/2.2/source-class-Doctrine.ORM.Mapping.ClassMetadataInfo.html 包含一个可能正是您需要的公共属性:

     222:     /**
     223:      * READ-ONLY: The field mappings of the class.
     224:      * Keys are field names and values are mapping definitions.
     225:      *
     226:      * The mapping definition array has the following values:
     227:      *
     228:      * - <b>fieldName</b> (string)
     229:      * The name of the field in the Entity.
     230:      *
     231:      * - <b>type</b> (string)
     232:      * The type name of the mapped field. Can be one of Doctrine's mapping types
     233:      * or a custom mapping type.
     234:      *
     235:      * - <b>columnName</b> (string, optional)
     236:      * The column name. Optional. Defaults to the field name.
     237:      *
     238:      * - <b>length</b> (integer, optional)
     239:      * The database length of the column. Optional. Default value taken from
     240:      * the type.
     241:      *
     242:      * - <b>id</b> (boolean, optional)
     243:      * Marks the field as the primary key of the entity. Multiple fields of an
     244:      * entity can have the id attribute, forming a composite key.
     245:      *
     246:      * - <b>nullable</b> (boolean, optional)
     247:      * Whether the column is nullable. Defaults to FALSE.
     248:      *
     249:      * - <b>columnDefinition</b> (string, optional, schema-only)
     250:      * The SQL fragment that is used when generating the DDL for the column.
     251:      *
     252:      * - <b>precision</b> (integer, optional, schema-only)
     253:      * The precision of a decimal column. Only valid if the column type is decimal.
     254:      *
     255:      * - <b>scale</b> (integer, optional, schema-only)
     256:      * The scale of a decimal column. Only valid if the column type is decimal.
     257:      *
     258:      * - <b>unique (string, optional, schema-only)</b>
     259:      * Whether a unique constraint should be generated for the column.
     260:      *
     261:      * @var array
     262:      */
     263:     public $fieldMappings = array();
    

    【讨论】:

      猜你喜欢
      • 2012-10-12
      • 2010-12-05
      • 2013-11-28
      • 1970-01-01
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 2018-10-15
      相关资源
      最近更新 更多