0

データベース スキーマ情報をデータベースに格納する必要があります。エンティティ名、名前空間、およびその他のオプションを格納する db_entity というテーブルが既にあります。このテーブルに関連して、entity_id、attribute_name、attribute_type、required などを持つテーブル entity_attributes が必要です。

スキーマ構造の作成は簡単ですが、データベース内のすべてのエンティティからすべてのフィールドを挿入するのは面倒な作業です。すべてのエンティティ アノテーションを解析して、すべてのフィールドをデータベース テーブルに作成できるようにするスクリプトを作成する方法はありますか?

最良の方法は、テーブル スキーマを更新する doctrine:schema:update に同様のコマンドを記述することです。

ありがとうございました。

4

1 に答える 1

0

doctrine メタデータ クラス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();
于 2013-10-18T17:58:36.250 に答える