19. Annotations Reference

Warning

警告

The annotation driver is deprecated and will be removed in version 3.0. It is strongly recommended to switch to one of the other mapping drivers.

アノテーション ドライバは非推奨であり、バージョン 3.0 で削除されます。他のマッピング ドライバのいずれかに切り替えることを強くお勧めします。

Note

ノート

To be able to use annotations, you will have to install an extra package called doctrine/annotations.

注釈を使用できるようにするには、doctrine/annotations という追加パッケージをインストールする必要があります。

You’ve probably used docblock annotations in some form already, most likely to provide documentation metadata for a tool like PHPDocumentor (@author, @link, …). Docblock annotations are a tool to embed metadata inside the documentation section which can then be processed by some tool. Doctrine ORM generalizes the concept of docblock annotations so that they can be used for any kind of metadata and so that it is easy to define new docblock annotations. In order to allow more involved annotation values and to reduce the chances of clashes with other docblock annotations, the Doctrine ORM docblock annotations feature an alternative syntax that is heavily inspired by the Annotation syntax introduced in Java 5.

PHPDocumentor (@author、@link など) のようなツールのドキュメント メタデータを提供するために、何らかの形式で docblock アノテーションを既に使用している可能性があります。 Docblock アノテーションは、ドキュメント セクション内にメタデータを埋め込むためのツールであり、その後何らかのツールで処理できます。 Doctrine ORM は、docblock アノテーションの概念を一般化して、あらゆる種類のメタデータに使用できるようにし、新しい docblock アノテーションを簡単に定義できるようにします。より複雑なアノテーション値を許可し、他の docblock アノテーションとの衝突の可能性を減らすために、Doctrine ORMdocblock アノテーションは、Java 5 で導入された Annotation 構文に大きく影響された代替構文を備えています。

The implementation of these enhanced docblock annotations is located in the doctrine/annotations package, but in the Doctrine\Common\Annotations namespace for backwards compatibility reasons. Note that doctrine/annotations is not required by Doctrine ORM, and you will need to require that package if you want to use annotations. Doctrine ORM docblock annotations support namespaces and nested annotations among other things. The Doctrine ORM defines its own set of docblock annotations for supplying object-relational mapping metadata.

これらの強化された docblock アノテーションの実装は doctrine/annotations パッケージにありますが、下位互換性のために Doctrine\Common\Annotations 名前空間にあります。 doctrine/annotations は DoctrineORM では必要ないことに注意してください。注釈を使用する場合は、そのパッケージを必要とする必要があります。 Doctrine ORM docblock アノテーションは、特に名前空間とネストされたアノテーションをサポートします。 Doctrine ORM は、オブジェクト リレーショナル マッピング メタデータを提供するための独自の docblock 注釈のセットを定義します。

Note

ノート

If you’re not comfortable with the concept of docblock annotations, don’t worry, as mentioned earlier Doctrine ORM provides XML and YAML alternatives and you could easily implement your own favourite mechanism for defining ORM metadata.

docblockannotation の概念に慣れていない場合でも、心配しないでください。前述のように、Doctrine ORM は XML と YAML の代替手段を提供し、ORM メタデータを定義するための独自のお気に入りのメカニズムを簡単に実装できます。

In this chapter a reference of every Doctrine ORM Annotation is given with short explanations on their context and usage.

この章では、Doctrine ORM Annotation のすべての参照が、そのコンテキストと使用法に関する短い説明とともに提供されます。

19.1. Index

19.2. Reference

19.2.1. @Column

Marks an annotated instance variable as “persistent”. It has to be inside the instance variables PHP DocBlock comment. Any value hold inside this variable will be saved to and loaded from the database as part of the lifecycle of the instance variables entity-class.

注釈付きインスタンス変数を「永続的」としてマークします。インスタンス変数 PHP DocBlock コメント内にある必要があります。この変数内に保持されている値は、インスタンス変数エンティティ クラスのライフサイクルの一部としてデータベースに保存され、データベースからロードされます。

Required attributes:

必須属性:

  • type: Name of the Doctrine Type which is converted between PHP and Database representation. Default to string or Type from PHP property type

    type: PHP とデータベース表現の間で変換される Doctrine Type の名前。デフォルトは文字列またはPHPプロパティタイプのタイプ

Optional attributes:

オプションの属性:

  • name: By default the property name is used for the database column name also, however the ‘name’ attribute allows you to determine the column name.

    name: デフォルトでは、プロパティ名はデータベースの列名にも使用されますが、'name' 属性を使用すると、列名を決定できます。

  • length: Used by the “string” type to determine its maximum length in the database. Doctrine does not validate the length of a string value for you.

    長さ: データベース内の最大長を決定するために「文字列」タイプによって使用されます。 Doctrine は astring 値の長さを検証しません。

  • precision: The precision for a decimal (exact numeric) column (applies only for decimal column), which is the maximum number of digits that are stored for the values.

    精度: 10 進数 (正確な数値) 列の精度 (10 進数列にのみ適用)。これは、値に対して格納される最大桁数です。

  • scale: The scale for a decimal (exact numeric) column (applies only for decimal column), which represents the number of digits to the right of the decimal point and must not be greater than precision.

    scale: 10 進数 (正確な数値) 列のスケール (10 進数列にのみ適用)。これは、小数点の右側の桁数を表し、precision より大きくしてはなりません。

  • unique: Boolean value to determine if the value of the column should be unique across all rows of the underlying entities table.

    unique: 列の値が基になるエンティティ テーブルのすべての行で一意である必要があるかどうかを決定するブール値。

  • nullable: Determines if NULL values allowed for this column. If not specified, default value is false.

    nullable: この列に NULL 値を許可するかどうかを決定します。指定しない場合、デフォルト値は false です。

  • insertable: Boolean value to determine if the column should be included when inserting a new row into the underlying entities table. If not specified, default value is true.

    insertable: 基になるエンティティ テーブルに新しい行を挿入するときに列を含める必要があるかどうかを決定するブール値。指定されていない場合、既定値は true です。

  • updatable: Boolean value to determine if the column should be included when updating the row of the underlying entities table. If not specified, default value is true.

    更新可能: 基になるエンティティ テーブルの行を更新するときに列を含める必要があるかどうかを決定するブール値。指定されていない場合、既定値は true です。

  • generated: An enum with the possible values ALWAYS, INSERT, NEVER. Is used after an INSERT or UPDATE statement to determine if the database generated this value and it needs to be fetched using a SELECT statement.

    generated: ALWAYS、INSERT、NEVER の可能な値を持つ列挙型。INSERT または UPDATE ステートメントの後に使用され、データベースがこの値を生成し、SELECT ステートメントを使用してフェッチする必要があるかどうかを判断します。

  • options: Array of additional options:

    options: 追加オプションの配列:

    • default: The default value to set for the column if no value is supplied.

      default: 値が指定されていない場合に列に設定するデフォルト値。

    • unsigned: Boolean value to determine if the column should be capable of representing only non-negative integers (applies only for integer column and might not be supported by all vendors).

      unsigned: 列が非負の整数のみを表すことができるかどうかを決定するブール値 (整数列にのみ適用され、すべてのベンダーでサポートされているわけではありません)。

    • fixed: Boolean value to determine if the specified length of a string column should be fixed or varying (applies only for string/binary column and might not be supported by all vendors).

      fixed: 文字列列の指定された長さを固定にするか可変にするかを決定するブール値 (文字列/バイナリ列にのみ適用され、すべてのベンダーでサポートされているわけではありません)。

    • comment: The comment of the column in the schema (might not be supported by all vendors).

      comment: スキーマ内の列のコメント (すべてのベンダーでサポートされているわけではありません)。

    • collation: The collation of the column (only supported by Drizzle, Mysql, PostgreSQL>=9.1, Sqlite and SQLServer).

      collat​​ion: 列の照合 (Drizzle、Mysql、PostgreSQL>=9.1、Sqlite、および SQLServer でのみサポートされます)。

    • check: Adds a check constraint type to the column (might not be supported by all vendors).

      check: 列にチェック制約タイプを追加します (すべてのベンダーでサポートされているわけではありません)。

  • columnDefinition: DDL SQL snippet that starts after the column name and specifies the complete (non-portable!) column definition. This attribute allows to make use of advanced RMDBS features. However you should make careful use of this feature and the consequences. SchemaTool will not detect changes on the column correctly anymore if you use “columnDefinition”.

    columnDefinition: 列名の後に開始し、完全な (移植不可!) 列定義を指定する DDL SQL スニペット。この属性により、高度な RMDBS 機能を利用できます。ただし、この機能とその結果を慎重に使用する必要があります。 「columnDefinition」を使用すると、SchemaTool は列の変更を正しく検出しなくなります。

    Additionally you should remember that the “type” attribute still handles the conversion between PHP and Database values. If you use this attribute on a column that is used for joins between tables you should also take a look at @JoinColumn.

    さらに、「type」属性は引き続き PHP とデータベース値の間の変換を処理することに注意してください。テーブル間の結合に使用される列でこの属性を使用する場合は、@JoinColumn も確認する必要があります。

Note

ノート

For more detailed information on each attribute, please refer to the DBAL Schema-Representation documentation.

各属性の詳細については、DBAL スキーマ表現のドキュメントを参照してください。

Examples:

例:

<?php
/**
 * @Column(type="string", length=32, unique=true, nullable=false)
 */
protected $username;

/**
 * @Column(type="string", columnDefinition="CHAR(2) NOT NULL")
 */
protected $country;

/**
 * @Column(type="decimal", precision=2, scale=1)
 */
protected $height;

/**
 * @Column(type="string", length=2, options={"fixed":true, "comment":"Initial letters of first and last name"})
 */
protected $initials;

/**
 * @Column(type="integer", name="login_count", nullable=false, options={"unsigned":true, "default":0})
 */
protected $loginCount;

/**
 * Generated column
 * @Column(type="string", name="user_fullname", insertable=false, updatable=false)
 * MySQL example: full_name char(41) GENERATED ALWAYS AS (concat(firstname,' ',lastname)),
 */
protected $fullname;

19.2.2. @ColumnResult

References name of a column in the SELECT clause of a SQL query. Scalar result types can be included in the query result by specifying this annotation in the metadata.

SQL クエリの SELECT 句で列の名前を参照します。メタデータでこの注釈を指定することにより、スカラー結果型をクエリ結果に含めることができます。

Required attributes:

必須属性:

  • name: The name of a column in the SELECT clause of a SQL query

    name: SQL クエリの SELECT 句の列の名前

19.2.3. @Cache

Add caching strategy to a root entity or a collection.

ルート エンティティまたはコレクションにキャッシュ戦略を追加します。

Optional attributes:

オプションの属性:

  • usage: One of READ_ONLY, READ_WRITE or NONSTRICT_READ_WRITE, By default this is READ_ONLY.

    使用法: READ_ONLY、READ_WRITE または NONSTRICT_READ_WRITE のいずれか。デフォルトでは、これは READ_ONLY です。

  • region: An specific region name

    region: 特定の地域名

19.2.4. @ChangeTrackingPolicy

The Change Tracking Policy annotation allows to specify how the Doctrine ORM UnitOfWork should detect changes in properties of entities during flush. By default each entity is checked according to a deferred implicit strategy, which means upon flush UnitOfWork compares all the properties of an entity to a previously stored snapshot. This works out of the box, however you might want to tweak the flush performance where using another change tracking policy is an interesting option.

Change Tracking Policy アノテーションを使用すると、Doctrine ORM UnitOfWork がフラッシュ中にエンティティのプロパティの変更を検出する方法を指定できます。デフォルトでは、各エンティティは、遅延された暗黙的な戦略に従ってチェックされます。つまり、フラッシュ時に UnitOfWork がエンティティのすべてのプロパティを以前に保存されたスナップショットと比較します。これはそのまま使用できますが、別の変更追跡ポリシーを使用することが興味深いオプションである場合、フラッシュのパフォーマンスを微調整したい場合があります。

The details on all the available change tracking policies can be found in the configuration section.

利用可能なすべての変更追跡ポリシーの詳細は、構成セクションにあります。

Example:

例:

<?php
/**
 * @Entity
 * @ChangeTrackingPolicy("DEFERRED_IMPLICIT")
 * @ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 * @ChangeTrackingPolicy("NOTIFY")
 */
class User {}

19.2.5. @CustomIdGenerator

This annotations allows you to specify a user-provided class to generate identifiers. This annotation only works when both @Id and @GeneratedValue(strategy=”CUSTOM”) are specified.

このアノテーションを使用すると、ユーザー提供のクラスを指定して識別子を生成できます。このアノテーションは、@Id と @GeneratedValue(strategy="CUSTOM") の両方が指定されている場合にのみ機能します。

Required attributes:

必須属性:

  • class: name of the class which should extend DoctrineORMIdAbstractIdGenerator

    class: DoctrineORMIdAbstractIdGenerator を拡張するクラスの名前

Example:

例:

<?php
/**
 * @Id
 * @Column(type="integer")
 * @GeneratedValue(strategy="CUSTOM")
 * @CustomIdGenerator(class="My\Namespace\MyIdGenerator")
 */
public $id;

19.2.6. @DiscriminatorColumn

This annotation is an optional annotation for the topmost/super class of an inheritance hierarchy. It specifies the details of the column which saves the name of the class, which the entity is actually instantiated as.

この注釈は、継承階層の最上位/スーパークラスのオプションの注釈です。エンティティが実際にインスタンス化されるクラスの名前を保存する列の詳細を指定します。

If this annotation is not specified, the discriminator column defaults to a string column of length 255 called dtype.

この注釈が指定されていない場合、識別子列はデフォルトで dtype と呼ばれる長さ 255 の文字列列になります。

Required attributes:

必須属性:

  • name: The column name of the discriminator. This name is also used during Array hydration as key to specify the class-name.

    name: 識別子の列名。この名前は、クラス名を指定するキーとして配列ハイドレーション中にも使用されます。

Optional attributes:

オプションの属性:

  • type: By default this is string.

    type: デフォルトでは、これは文字列です。

  • length: By default this is 255.

    長さ: デフォルトでは、これは 255 です。

19.2.7. @DiscriminatorMap

The discriminator map is a required annotation on the topmost/super class in an inheritance hierarchy. Its only argument is an array which defines which class should be saved under which name in the database. Keys are the database value and values are the classes, either as fully- or as unqualified class names depending on whether the classes are in the namespace or not.

識別子マップは、継承階層の最上位/スーパー クラスに必要な注釈です。その唯一の引数は、どのクラスをどの名前でデータベースに保存するかを定義する配列です。キーはデータベースの値であり、値はクラスであり、クラスが名前空間にあるかどうかに応じて、完全なクラス名または非修飾クラス名のいずれかになります。

<?php
/**
 * @Entity
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
 */
class Person
{
    // ...
}

19.2.8. @Embeddable

The embeddable annotation is required on a class, in order to make it embeddable inside an entity. It works together with the @Embedded annotation to establish the relationship between the two classes.

エンティティ内で itembeddable を作成するには、クラスに Embeddable アノテーションが必要です。 @Embeddedannotation と連携して、2 つのクラス間の関係を確立します。

<?php

/**
 * @Embeddable
 */
class Address
{
// ...
class User
{
    /**
     * @Embedded(class = "Address")
     */
    private $address;

19.2.9. @Embedded

The embedded annotation is required on an entity’s member variable, in order to specify that it is an embedded class.

埋め込みクラスであることを指定するには、エンティティのメンバー変数に埋め込みアノテーションが必要です。

Required attributes:

必須属性:

  • class: The embeddable class. You can omit this value if you use a PHP property type instead.

    class: 埋め込み可能なクラス。代わりに PHP プロパティ タイプを使用する場合は、この値を省略できます。

<?php

// ...
class User
{
    /**
     * @Embedded(class = "Address")
     */
    private $address;

/**
 * @Embeddable
 */
class Address
{
// ...

19.2.10. @Entity

Required annotation to mark a PHP class as an entity. Doctrine manages the persistence of all classes marked as entities.

PHP クラスをエンティティとしてマークするために必要なアノテーション。 Doctrine は、エンティティとしてマークされたすべてのクラスの永続性を管理します。

Optional attributes:

オプションの属性:

  • repositoryClass: Specifies the FQCN of a subclass of the EntityRepository. Use of repositories for entities is encouraged to keep specialized DQL and SQL operations separated from the Model/Domain Layer.

    repositoryClass: theEntityRepository のサブクラスの FQCN を指定します。エンティティにリポジトリを使用して、特殊な DQL および SQL 操作を Model/DomainLayer から分離しておくことをお勧めします。

  • readOnly: Specifies that this entity is marked as read only and not considered for change-tracking. Entities of this type can be persisted and removed though.

    readOnly: このエンティティが読み取り専用としてマークされ、変更の追跡が考慮されないことを指定します。ただし、このタイプのエンティティは永続化および削除できます。

Example:

例:

<?php
/**
 * @Entity(repositoryClass="MyProject\UserRepository", readOnly=true)
 */
class User
{
    // ...
}

19.2.11. @EntityResult

References an entity in the SELECT clause of a SQL query. If this annotation is used, the SQL statement should select all of the columns that are mapped to the entity object. This should include foreign key columns to related entities. The results obtained when insufficient data is available are undefined.

SQL クエリの SELECT 句でエンティティを参照します。この注釈を使用する場合、SQL ステートメントは、エンティティ オブジェクトにマップされているすべての列を選択する必要があります。これには、関連するエンティティへの外部キー列が含まれている必要があります。不十分な場合に得られる結果利用可能なデータは未定義です。

Required attributes:

必須属性:

  • entityClass: The class of the result.

    entityClass: 結果のクラス。

Optional attributes:

オプションの属性:

  • fields: Array of @FieldResult, Maps the columns specified in the SELECT list of the query to the properties or fields of the entity class.

    fields: @FieldResult の配列、クエリの SELECT リストで指定された列をエンティティ クラスのプロパティまたはフィールドにマップします。

  • discriminatorColumn: Specifies the column name of the column in the SELECT list that is used to determine the type of the entity instance.

    discriminatorColumn: エンティティ インスタンスの型を決定するために使用される SELECT リスト内の列の列名を指定します。

19.2.12. @FieldResult

Is used to map the columns specified in the SELECT list of the query to the properties or fields of the entity class.

クエリの SELECT リストで指定された列をエンティティ クラスのプロパティまたはフィールドにマップするために使用されます。

Required attributes:

必須属性:

  • name: Name of the persistent field or property of the class.

    name: クラスの永続フィールドまたはプロパティの名前。

Optional attributes:

オプションの属性:

  • column: Name of the column in the SELECT clause.

    column: SELECT 句の列の名前。

19.2.13. @GeneratedValue

Specifies which strategy is used for identifier generation for an instance variable which is annotated by @Id. This annotation is optional and only has meaning when used in conjunction with @Id.

@Id によって注釈が付けられたインスタンス変数の識別子の生成に使用される戦略を指定します。この注釈はオプションであり、@Id と組み合わせて使用​​する場合にのみ意味があります。

If this annotation is not specified with @Id the NONE strategy is used as default.

この注釈が @Id で指定されていない場合、NONE 戦略がデフォルトとして使用されます。

Optional attributes:

オプションの属性:

  • strategy: Set the name of the identifier generation strategy. Valid values are AUTO, SEQUENCE, IDENTITY, UUID (deprecated), CUSTOM and NONE, explained in the Identifier Generation Strategies section. If not specified, default value is AUTO.

    戦略: 識別子生成戦略の名前を設定します。有効な値は、AUTO、SEQUENCE、IDENTITY、UUID (非推奨)、CUSTOM、および NONE で、識別子生成戦略セクションで説明されています。指定されていない場合、デフォルト値は AUTO です。

Example:

例:

<?php
/**
 * @Id
 * @Column(type="integer")
 * @GeneratedValue(strategy="IDENTITY")
 */
protected $id = null;

19.2.14. @HasLifecycleCallbacks

Annotation which has to be set on the entity-class PHP DocBlock to notify Doctrine that this entity has entity lifecycle callback annotations set on at least one of its methods. Using @PostLoad, @PrePersist, @PostPersist, @PreRemove, @PostRemove, @PreUpdate or @PostUpdate without this marker annotation will make Doctrine ignore the callbacks.

エンティティ クラスの PHP DocBlock に設定する必要があるアノテーションは、このエンティティの少なくとも 1 つのメソッドにエンティティ ライフサイクル コールバック アノテーションが設定されていることを Doctrine に通知します。 @PostLoad、@PrePersist、@PostPersist、@PreRemove、@PostRemove、@PreUpdate または @PostUpdate をこのマーカー アノテーションなしで使用すると、Doctrine はコールバックを無視します。

Example:

例:

<?php
/**
 * @Entity
 * @HasLifecycleCallbacks
 */
class User
{
    /**
     * @PostPersist
     */
    public function sendOptinMail() {}
}

19.2.15. @Index

Annotation is used inside the @Table annotation on the entity-class level. It provides a hint to the SchemaTool to generate a database index on the specified table columns. It only has meaning in the SchemaTool schema generation context.

注釈は、エンティティ クラス レベルの @Table 注釈内で使用されます。これは、指定されたテーブル列にデータベース インデックスを生成するためのヒントを SchemaTool に提供します。これは、SchemaTool スキーマ生成コンテキストでのみ意味を持ちます。

Required attributes:

必須属性:

  • name: Name of the Index

    name: インデックスの名前

  • fields: Array of fields. Exactly one of fields, columns is required.

    fields: フィールドの配列。フィールド、列の 1 つだけが必要です。

  • columns: Array of columns. Exactly one of fields, columns is required.

    列: 列の配列。フィールド、列の 1 つだけが必要です。

Optional attributes:

オプションの属性:

  • options: Array of platform specific options:

    options: プラットフォーム固有のオプションの配列:

    • where: SQL WHERE condition to be used for partial indexes. It will only have effect on supported platforms.

      where: 部分インデックスに使用する SQL WHERE 条件。サポートされているプラ​​ットフォームでのみ効果があります。

Basic example:

基本的な例:

<?php
/**
 * @Entity
 * @Table(name="ecommerce_products",indexes={@Index(name="search_idx", columns={"name", "email"})})
 */
class ECommerceProduct
{
}

Basic example using fields:

フィールドを使用した基本的な例:

<?php
/**
 * @Entity
 * @Table(name="ecommerce_products",indexes={@Index(name="search_idx", fields={"name", "email"})})
 */
class ECommerceProduct
{
}

Example with partial indexes:

部分インデックスの例:

<?php
/**
 * @Entity
 * @Table(name="ecommerce_products",indexes={@Index(name="search_idx", columns={"name", "email"}, options={"where": "(((id IS NOT NULL) AND (name IS NULL)) AND (email IS NULL))"})})
 */
class ECommerceProduct
{
}

19.2.16. @Id

The annotated instance variable will be marked as entity identifier, the primary key in the database. This annotation is a marker only and has no required or optional attributes. For entities that have multiple identifier columns each column has to be marked with @Id.

注釈付きインスタンス変数は、データベースの主キーであるエンティティ識別子としてマークされます。この注釈はマーカーのみであり、必須またはオプションの属性はありません。各列に複数の識別子列がある Forentities は、@Id でマークする必要があります。

Example:

例:

<?php
/**
 * @Id
 * @Column(type="integer")
 */
protected $id = null;

19.2.17. @InheritanceType

In an inheritance hierarchy you have to use this annotation on the topmost/super class to define which strategy should be used for inheritance. Currently Single Table and Class Table Inheritance are supported.

継承階層では、最上位/スーパークラスでこの注釈を使用して、継承に使用する戦略を定義する必要があります。現在、単一テーブルとクラス テーブルの継承がサポートされています。

This annotation has always been used in conjunction with the @DiscriminatorMap and @DiscriminatorColumn annotations.

このアノテーションは、常に @DiscriminatorMap および @DiscriminatorColumn アノテーションと組み合わせて使用​​されてきました。

Examples:

例:

<?php
/**
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
 */
class Person
{
    // ...
}

/**
 * @Entity
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
 */
class Person
{
    // ...
}

19.2.18. @JoinColumn

This annotation is used in the context of relations in @ManyToOne, @OneToOne fields and in the Context of @JoinTable nested inside a @ManyToMany. If this annotation or both name and referencedColumnName are missing they will be computed considering the field’s name and the current naming strategy.

この注釈は、@ManyToOne、@OneToOne フィールドのリレーションのコンテキスト、および @ManyToMany 内にネストされた @JoinTable のコンテキストで使用されます。この注釈または name と referencedColumnName の両方が欠落している場合、それらはフィールドの名前と現在の命名戦略を考慮して計算されます。

Optional attributes:

オプションの属性:

  • name: Column name that holds the foreign key identifier for this relation. In the context of @JoinTable it specifies the column name in the join table.

    name: この関係の外部キー識別子を保持する列名。 @JoinTable のコンテキストでは、結合テーブルの列名を指定します。

  • referencedColumnName: Name of the primary key identifier that is used for joining of this relation. Defaults to id.

    referencedColumnName: この関係の結合に使用される主キー識別子の名前。デフォルトは ID です。

  • unique: Determines whether this relation is exclusive between the affected entities and should be enforced as such on the database constraint level. Defaults to false.

    unique: この関係が、影響を受けるエンティティ間で排他的であり、データベース制約レベルでそのように強制する必要があるかどうかを決定します。デフォルトは false です。

  • nullable: Determine whether the related entity is required, or if null is an allowed state for the relation. Defaults to true.

    nullable: 関連するエンティティが必須かどうか、または null の場合は関係の許可された状態かどうかを決定します。デフォルトは true です。

  • onDelete: Cascade Action (Database-level)

    onDelete: カスケード アクション (データベース レベル)

  • columnDefinition: DDL SQL snippet that starts after the column name and specifies the complete (non-portable!) column definition. This attribute enables the use of advanced RMDBS features. Using this attribute on @JoinColumn is necessary if you need slightly different column definitions for joining columns, for example regarding NULL/NOT NULL defaults. However by default a “columnDefinition” attribute on @Column also sets the related @JoinColumn’s columnDefinition. This is necessary to make foreign keys work.

    columnDefinition: columnname の後に開始し、完全な (移植不可!) 列定義を指定する DDL SQL スニペット。この属性により、高度な RMDBS 機能を使用できるようになります。 @JoinColumn でこの属性を使用する必要があるのは、たとえば NULL/NOT NULL デフォルトに関して、列を結合するためにわずかに異なる列定義が必要な場合です。ただし、デフォルトでは、@Column の「columnDefinition」属性は、関連する @JoinColumn の columnDefinition も設定します。これは、外部キーを機能させるために必要です。

Example:

例:

<?php
/**
 * @OneToOne(targetEntity="Customer")
 * @JoinColumn(name="customer_id", referencedColumnName="id")
 */
private $customer;

19.2.19. @JoinColumns

An array of @JoinColumn annotations for a @ManyToOne or @OneToOne relation with an entity that has multiple identifiers.

複数の識別子を持つエンティティを持つ @ManyToOne または @OneToOnerelation の @JoinColumn アノテーションの配列。

19.2.20. @JoinTable

Using @OneToMany or @ManyToMany on the owning side of the relation requires to specify the @JoinTable annotation which describes the details of the database join table. If you do not specify @JoinTable on these relations reasonable mapping defaults apply using the affected table and the column names.

リレーションの所有側で @OneToMany または @ManyToMany を使用するには、データベース結合テーブルの詳細を記述する @JoinTable アノテーションを指定する必要があります。これらのリレーションで @JoinTable を指定しない場合、影響を受けるテーブルと列名を使用して、妥当なマッピングのデフォルトが適用されます。

Optional attributes:

オプションの属性:

  • name: Database name of the join-table

    name: 結合テーブルのデータベース名

  • joinColumns: An array of @JoinColumn annotations describing the join-relation between the owning entities table and the join table.

    joinColumns: 所有エンティティ テーブルと結合テーブルの間の結合関係を記述する @JoinColumn アノテーションの配列。

  • inverseJoinColumns: An array of @JoinColumn annotations describing the join-relation between the inverse entities table and the join table.

    inverseJoinColumns: 逆エンティティ テーブルと結合テーブルの間の結合関係を記述する @JoinColumn アノテーションの配列。

Example:

例:

<?php
/**
 * @ManyToMany(targetEntity="Phonenumber")
 * @JoinTable(name="users_phonenumbers",
 *      joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
 *      inverseJoinColumns={@JoinColumn(name="phonenumber_id", referencedColumnName="id", unique=true)}
 * )
 */
public $phonenumbers;

19.2.21. @ManyToOne

Defines that the annotated instance variable holds a reference that describes a many-to-one relationship between two entities.

注釈付きインスタンス変数が、2 つのエンティティ間の多対 1 の関係を記述する参照を保持することを定義します。

Required attributes:

必須属性:

  • targetEntity: FQCN of the referenced target entity. Can be the unqualified class name if both classes are in the same namespace. You can omit this value if you use a PHP property type instead. IMPORTANT: No leading backslash!

    targetEntity: 参照されるターゲット エンティティの FQCN。両方のクラスが同じ名前空間にある場合は、非修飾クラス名にすることができます。代わりに PHP プロパティ タイプを使用する場合は、この値を省略できます。重要: 先頭のバックスラッシュは使用しないでください。

Optional attributes:

オプションの属性:

  • cascade: Cascade Option

    cascade: カスケードオプション

  • fetch: One of LAZY or EAGER

    fetch: LAZY または EAGER のいずれか

  • inversedBy - The inversedBy attribute designates the field in the entity that is the inverse side of the relationship.

    inversedBy - inversedBy 属性は、関係の逆側であるエンティティ内のフィールドを指定します。

Example:

例:

<?php
/**
 * @ManyToOne(targetEntity="Cart", cascade={"all"}, fetch="EAGER")
 */
private $cart;

19.2.22. @ManyToMany

Defines that the annotated instance variable holds a many-to-many relationship between two entities. @JoinTable is an additional, optional annotation that has reasonable default configuration values using the table and names of the two related entities.

注釈付きインスタンス変数が 2 つのエンティティ間の多対多の関係を保持することを定義します。 @JoinTable は、関連する 2 つのエンティティのテーブルと名前を使用して妥当なデフォルト設定値を持つ、追加のオプションのアノテーションです。

Required attributes:

必須属性:

  • targetEntity: FQCN of the referenced target entity. Can be the unqualified class name if both classes are in the same namespace. IMPORTANT: No leading backslash!

    targetEntity: 参照されるターゲット エンティティの FQCN。両方のクラスが同じ名前空間にある場合は、非修飾クラス名にすることができます。重要: 先頭のバックスラッシュは使用しないでください。

Optional attributes:

オプションの属性:

  • mappedBy: This option specifies the property name on the targetEntity that is the owning side of this relation. It is a required attribute for the inverse side of a relationship.

    MappedBy: このオプションは、この関係の所有側である targetEntity のプロパティ名を指定します。リレーションシップの逆側の必須属性です。

  • inversedBy: The inversedBy attribute designates the field in the entity that is the inverse side of the relationship.

    inversedBy: inversedBy 属性は、関係の逆側であるエンティティ内のフィールドを指定します。

  • cascade: Cascade Option

    cascade: カスケードオプション

  • fetch: One of LAZY, EXTRA_LAZY or EAGER

    fetch: LAZY、EXTRA_LAZY、または EAGER のいずれか

  • indexBy: Index the collection by a field on the target entity.

    indexBy: ターゲット エンティティのフィールドによってコレクションにインデックスを付けます。

Note

ノート

For ManyToMany bidirectional relationships either side may be the owning side (the side that defines the @JoinTable and/or does not make use of the mappedBy attribute, thus using a default join table).

ManyToMany の双方向関係の場合、いずれかの側が所有側になる可能性があります (@JoinTable を定義する側、および/または mappingBy 属性を使用しないため、defaultjoin テーブルを使用する側)。

Example:

例:

<?php
/**
 * Owning Side
 *
 * @ManyToMany(targetEntity="Group", inversedBy="features")
 * @JoinTable(name="user_groups",
 *      joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
 *      inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
 *      )
 */
private $groups;

/**
 * Inverse Side
 *
 * @ManyToMany(targetEntity="User", mappedBy="groups")
 */
private $features;

19.2.23. @MappedSuperclass

A mapped superclass is an abstract or concrete class that provides persistent entity state and mapping information for its subclasses, but which is not itself an entity. This annotation is specified on the Class docblock and has no additional attributes.

マップされたスーパークラスは、永続的なエンティティの状態とそのサブクラスのマッピング情報を提供する抽象クラスまたは具象クラスですが、それ自体はエンティティではありません。この注釈は Class docblock で指定され、追加の属性はありません。

The @MappedSuperclass annotation cannot be used in conjunction with @Entity. See the Inheritance Mapping section for more details on the restrictions of mapped superclasses.

@MappedSuperclass アノテーションは、@Entity と組み合わせて使用​​することはできません。マップされたスーパークラスの制限の詳細については、継承マッピングのセクションを参照してください。

Optional attributes:

オプションの属性:

  • repositoryClass: Specifies the FQCN of a subclass of the EntityRepository. That will be inherited for all subclasses of that Mapped Superclass.

    repositoryClass: EntityRepository のサブクラスの FQCN を指定します。これは、Mapped Superclass のすべてのサブクラスに継承されます。

Example:

例:

<?php
/**
 * @MappedSuperclass
 */
class MappedSuperclassBase
{
    // ... fields and methods
}

/**
 * @Entity
 */
class EntitySubClassFoo extends MappedSuperclassBase
{
    // ... fields and methods
}

19.2.24. @NamedNativeQuery

Note

ノート

Named Native Queries are deprecated as of version 2.9 and will be removed in ORM 3.0

名前付きネイティブ クエリはバージョン 2.9 で非推奨になり、ORM 3.0 で削除されます

Is used to specify a native SQL named query. The NamedNativeQuery annotation can be applied to an entity or mapped superclass.

ネイティブ SQL 名前付きクエリを指定するために使用されます。NamedNativeQuery アノテーションは、エンティティまたはマップされたスーパークラスに適用できます。

Required attributes:

必須属性:

  • name: The name used to refer to the query with the EntityManager methods that create query objects.

    name: クエリ オブジェクトを作成する EntityManager メソッドでクエリを参照するために使用される名前。

  • query: The SQL query string.

    query: SQL クエリ文字列。

Optional attributes:

オプションの属性:

  • resultClass: The class of the result.

    resultClass: 結果のクラス。

  • resultSetMapping: The name of a SqlResultSetMapping, as defined in metadata.

    resultSetMapping: メタデータで定義されている SqlResultSetMapping の名前。

Example:

例:

<?php
/**
 * @NamedNativeQueries({
 *      @NamedNativeQuery(
 *          name            = "fetchJoinedAddress",
 *          resultSetMapping= "mappingJoinedAddress",
 *          query           = "SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?"
 *      ),
 * })
 * @SqlResultSetMappings({
 *      @SqlResultSetMapping(
 *          name    = "mappingJoinedAddress",
 *          entities= {
 *              @EntityResult(
 *                  entityClass = "__CLASS__",
 *                  fields      = {
 *                      @FieldResult(name = "id"),
 *                      @FieldResult(name = "name"),
 *                      @FieldResult(name = "status"),
 *                      @FieldResult(name = "address.zip"),
 *                      @FieldResult(name = "address.city"),
 *                      @FieldResult(name = "address.country"),
 *                      @FieldResult(name = "address.id", column = "a_id"),
 *                  }
 *              )
 *          }
 *      )
 * })
 */
class User
{
    /** @Id @Column(type="integer") @GeneratedValue */
    public $id;

    /** @Column(type="string", length=50, nullable=true) */
    public $status;

    /** @Column(type="string", length=255, unique=true) */
    public $username;

    /** @Column(type="string", length=255) */
    public $name;

    /** @OneToOne(targetEntity="Address") */
    public $address;

    // ....
}

19.2.25. @OneToOne

The @OneToOne annotation works almost exactly as the @ManyToOne with one additional option which can be specified. The configuration defaults for @JoinColumn using the target entity table and primary key column names apply here too.

@OneToOne アノテーションは、@ManyToOne とほぼ同じように機能し、指定可能な追加オプションが 1 つあります。ターゲット エンティティ テーブルと主キー列名を使用する @JoinColumn の構成のデフォルトは、ここにも適用されます。

Required attributes:

必須属性:

  • targetEntity: FQCN of the referenced target entity. Can be the unqualified class name if both classes are in the same namespace. When typed properties are used it is inherited from PHP type. IMPORTANT: No leading backslash!

    targetEntity: 参照されるターゲット エンティティの FQCN。両方のクラスが同じ名前空間にある場合は、非修飾クラス名にすることができます。型指定されたプロパティを使用すると、PHP 型から継承されます。

Optional attributes:

オプションの属性:

  • cascade: Cascade Option

    cascade: カスケードオプション

  • fetch: One of LAZY or EAGER

    fetch: LAZY または EAGER のいずれか

  • orphanRemoval: Boolean that specifies if orphans, inverse OneToOne entities that are not connected to any owning instance, should be removed by Doctrine. Defaults to false.

    orphanRemoval: どの所有インスタンスにも接続されていない孤立した inverseOneToOne エンティティを Doctrine によって削除する必要があるかどうかを指定するブール値。デフォルトは false です。

  • inversedBy: The inversedBy attribute designates the field in the entity that is the inverse side of the relationship.

    inversedBy: inversedBy 属性は、関係の逆側であるエンティティ内のフィールドを指定します。

Example:

例:

<?php
/**
 * @OneToOne(targetEntity="Customer")
 * @JoinColumn(name="customer_id", referencedColumnName="id")
 */
private $customer;

19.2.26. @OneToMany

Required attributes:

必須属性:

  • targetEntity: FQCN of the referenced target entity. Can be the unqualified class name if both classes are in the same namespace. IMPORTANT: No leading backslash!

    targetEntity: 参照されるターゲット エンティティの FQCN。両方のクラスが同じ名前空間にある場合は、非修飾クラス名にすることができます。重要: 先頭のバックスラッシュは使用しないでください。

Optional attributes:

オプションの属性:

  • cascade: Cascade Option

    cascade: カスケードオプション

  • orphanRemoval: Boolean that specifies if orphans, inverse OneToOne entities that are not connected to any owning instance, should be removed by Doctrine. Defaults to false.

    orphanRemoval: どの所有インスタンスにも接続されていない孤立した inverseOneToOne エンティティを Doctrine によって削除する必要があるかどうかを指定するブール値。デフォルトは false です。

  • mappedBy: This option specifies the property name on the targetEntity that is the owning side of this relation. Its a required attribute for the inverse side of a relationship.

    MappedBy: このオプションは、この関係の所有側である targetEntity のプロパティ名を指定します。リレーションシップの逆側に必要な属性です。

  • fetch: One of LAZY, EXTRA_LAZY or EAGER.

    fetch: LAZY、EXTRA_LAZY、または EAGER のいずれか。

  • indexBy: Index the collection by a field on the target entity.

    indexBy: ターゲット エンティティのフィールドによってコレクションにインデックスを付けます。

Example:

例:

<?php
/**
 * @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist", "remove", "merge"}, orphanRemoval=true)
 */
public $phonenumbers;

19.2.27. @OrderBy

Optional annotation that can be specified with a @ManyToMany or @OneToMany annotation to specify by which criteria the collection should be retrieved from the database by using an ORDER BY clause.

@ManyToMany または @OneToManyannotation で指定できるオプションの注釈で、ORDER BY 句を使用してデータベースからコレクションを取得する基準を指定します。

This annotation requires a single non-attributed value with an DQL snippet:

この注釈には、DQLsnippet を含む単一の属性のない値が必要です。

Example:

例:

<?php
/**
 * @ManyToMany(targetEntity="Group")
 * @OrderBy({"name" = "ASC"})
 */
private $groups;

The DQL Snippet in OrderBy is only allowed to consist of unqualified, unquoted field names and of an optional ASC/DESC positional statement. Multiple Fields are separated by a comma (,). The referenced field names have to exist on the targetEntity class of the @ManyToMany or @OneToMany annotation.

OrderBy の DQL スニペットは、修飾も引用符も付けられていないフィールド名と、オプションの ASC/DESC 位置ステートメントのみで構成できます。複数のフィールドはコンマ (,) で区切ります。参照されるフィールド名は、@ManyToMany または @OneToMany アノテーションの targetEntityclass に存在する必要があります。

19.2.28. @PostLoad

Marks a method on the entity to be called as a @PostLoad event. Only works with @HasLifecycleCallbacks in the entity class PHP DocBlock.

@PostLoad イベントとして呼び出されるエンティティのメソッドをマークします。エンティティ クラス PHPDocBlock の @HasLifecycleCallbacks でのみ機能します。

19.2.29. @PostPersist

Marks a method on the entity to be called as a @PostPersist event. Only works with @HasLifecycleCallbacks in the entity class PHP DocBlock.

@PostPersist イベントとして呼び出されるエンティティのメソッドをマークします。エンティティ クラス PHPDocBlock の @HasLifecycleCallbacks でのみ機能します。

19.2.30. @PostRemove

Marks a method on the entity to be called as a @PostRemove event. Only works with @HasLifecycleCallbacks in the entity class PHP DocBlock.

@PostRemove イベントとして呼び出されるエンティティのメソッドをマークします。エンティティ クラス PHPDocBlock の @HasLifecycleCallbacks でのみ機能します。

19.2.31. @PostUpdate

Marks a method on the entity to be called as a @PostUpdate event. Only works with @HasLifecycleCallbacks in the entity class PHP DocBlock.

@PostUpdate イベントとして呼び出されるエンティティのメソッドをマークします。エンティティ クラス PHPDocBlock の @HasLifecycleCallbacks でのみ機能します。

19.2.32. @PrePersist

Marks a method on the entity to be called as a @PrePersist event. Only works with @HasLifecycleCallbacks in the entity class PHP DocBlock.

@PrePersist イベントとして呼び出されるエンティティのメソッドをマークします。エンティティ クラス PHPDocBlock の @HasLifecycleCallbacks でのみ機能します。

19.2.33. @PreRemove

Marks a method on the entity to be called as a @PreRemove event. Only works with @HasLifecycleCallbacks in the entity class PHP DocBlock.

@PreRemove イベントとして呼び出されるエンティティのメソッドをマークします。エンティティ クラス PHPDocBlock の @HasLifecycleCallbacks でのみ機能します。

19.2.34. @PreUpdate

Marks a method on the entity to be called as a @PreUpdate event. Only works with @HasLifecycleCallbacks in the entity class PHP DocBlock.

@PreUpdate イベントとして呼び出されるエンティティのメソッドをマークします。エンティティ クラス PHPDocBlock の @HasLifecycleCallbacks でのみ機能します。

19.2.35. @SequenceGenerator

For use with @GeneratedValue(strategy=”SEQUENCE”) this annotation allows to specify details about the sequence, such as the increment size and initial values of the sequence.

@GeneratedValue(strategy="SEQUENCE") で使用する場合、このアノテーションを使用すると、シーケンスのインクリメント サイズや初期値など、シーケンスに関する詳細を指定できます。

Required attributes:

必須属性:

  • sequenceName: Name of the sequence

    sequenceName: シーケンスの名前

Optional attributes:

オプションの属性:

  • allocationSize: Increment the sequence by the allocation size when its fetched. A value larger than 1 allows optimization for scenarios where you create more than one new entity per request. Defaults to 10

    allocationSize: 取得時に割り当てサイズだけシーケンスをインクリメントします。 1 より大きい値を指定すると、リクエストごとに複数の新しいエンティティを作成するシナリオの最適化が可能になります。デフォルトは 10 です。

  • initialValue: Where the sequence starts, defaults to 1.

    initialValue: シーケンスが開始する場所。デフォルトは 1 です。

Example:

例:

<?php
/**
 * @Id
 * @GeneratedValue(strategy="SEQUENCE")
 * @Column(type="integer")
 * @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100)
 */
protected $id = null;

19.2.36. @SqlResultSetMapping

The SqlResultSetMapping annotation is used to specify the mapping of the result of a native SQL query. The SqlResultSetMapping annotation can be applied to an entity or mapped superclass.

SqlResultSetMapping アノテーションは、ネイティブ SQL クエリの結果のマッピングを指定するために使用されます。SqlResultSetMapping アノテーションは、エンティティまたはマップされたスーパークラスに適用できます。

Required attributes:

必須属性:

  • name: The name given to the result set mapping, and used to refer to it in the methods of the Query API.

    name: 結果セットのマッピングに付けられ、クエリ API のメソッドで参照するために使用される名前。

Optional attributes:

オプションの属性:

  • entities: Array of @EntityResult, Specifies the result set mapping to entities.

    entities: @EntityResult の配列。エンティティへの結果セットのマッピングを指定します。

  • columns: Array of @ColumnResult, Specifies the result set mapping to scalar values.

    columns: @ColumnResult の配列。スカラー値への結果セットのマッピングを指定します。

Example:

例:

<?php
/**
 * @NamedNativeQueries({
 *      @NamedNativeQuery(
 *          name            = "fetchUserPhonenumberCount",
 *          resultSetMapping= "mappingUserPhonenumberCount",
 *          query           = "SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username"
 *      ),
 *      @NamedNativeQuery(
 *          name            = "fetchMultipleJoinsEntityResults",
 *          resultSetMapping= "mappingMultipleJoinsEntityResults",
 *          query           = "SELECT u.id AS u_id, u.name AS u_name, u.status AS u_status, a.id AS a_id, a.zip AS a_zip, a.country AS a_country, COUNT(p.phonenumber) AS numphones FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id INNER JOIN cms_phonenumbers p ON u.id = p.user_id GROUP BY u.id, u.name, u.status, u.username, a.id, a.zip, a.country ORDER BY u.username"
 *      ),
 * })
 * @SqlResultSetMappings({
 *      @SqlResultSetMapping(
 *          name    = "mappingUserPhonenumberCount",
 *          entities= {
 *              @EntityResult(
 *                  entityClass = "User",
 *                  fields      = {
 *                      @FieldResult(name = "id"),
 *                      @FieldResult(name = "name"),
 *                      @FieldResult(name = "status"),
 *                  }
 *              )
 *          },
 *          columns = {
 *              @ColumnResult("numphones")
 *          }
 *      ),
 *      @SqlResultSetMapping(
 *          name    = "mappingMultipleJoinsEntityResults",
 *          entities= {
 *              @EntityResult(
 *                  entityClass = "__CLASS__",
 *                  fields      = {
 *                      @FieldResult(name = "id",       column="u_id"),
 *                      @FieldResult(name = "name",     column="u_name"),
 *                      @FieldResult(name = "status",   column="u_status"),
 *                  }
 *              ),
 *              @EntityResult(
 *                  entityClass = "Address",
 *                  fields      = {
 *                      @FieldResult(name = "id",       column="a_id"),
 *                      @FieldResult(name = "zip",      column="a_zip"),
 *                      @FieldResult(name = "country",  column="a_country"),
 *                  }
 *              )
 *          },
 *          columns = {
 *              @ColumnResult("numphones")
 *          }
 *      )
 *})
 */
 class User
{
    /** @Id @Column(type="integer") @GeneratedValue */
    public $id;

    /** @Column(type="string", length=50, nullable=true) */
    public $status;

    /** @Column(type="string", length=255, unique=true) */
    public $username;

    /** @Column(type="string", length=255) */
    public $name;

    /** @OneToMany(targetEntity="Phonenumber") */
    public $phonenumbers;

    /** @OneToOne(targetEntity="Address") */
    public $address;

    // ....
}

19.2.37. @Table

Annotation describes the table an entity is persisted in. It is placed on the entity-class PHP DocBlock and is optional. If it is not specified the table name will default to the entity’s unqualified classname.

Annotation は、エンティティが永続化されるテーブルを記述します。これは、エンティティ クラスの PHP DocBlock に配置され、オプションです。指定されていない場合、テーブル名はデフォルトでエンティティの修飾されていないクラス名になります。

Required attributes:

必須属性:

  • name: Name of the table

    name: テーブルの名前

Optional attributes:

オプションの属性:

  • indexes: Array of @Index annotations

    インデックス: @Index アノテーションの配列

  • uniqueConstraints: Array of @UniqueConstraint annotations.

    uniqueConstraints: @UniqueConstraint アノテーションの配列。

  • schema: Name of the schema the table lies in.

    schema: テーブルがあるスキーマの名前。

Example:

例:

<?php
/**
 * @Entity
 * @Table(name="user",
 *      uniqueConstraints={@UniqueConstraint(name="user_unique",columns={"username"})},
 *      indexes={@Index(name="user_idx", columns={"email"})}
 *      schema="schema_name"
 * )
 */
class User { }

19.2.38. @UniqueConstraint

Annotation is used inside the @Table annotation on the entity-class level. It allows to hint the SchemaTool to generate a database unique constraint on the specified table columns. It only has meaning in the SchemaTool schema generation context.

注釈は、エンティティ クラス レベルの @Table 注釈内で使用されます。これにより、指定されたテーブル列に対してデータベースの一意の制約を生成するよう SchemaTool にヒントを与えることができます。これは、SchemaTool スキーマ生成コンテキストでのみ意味を持ちます。

Required attributes:

必須属性:

  • name: Name of the Index

    name: インデックスの名前

  • fields: Array of fields. Exactly one of fields, columns is required.

    fields: フィールドの配列。フィールド、列の 1 つだけが必要です。

  • columns: Array of columns. Exactly one of fields, columns is required.

    列: 列の配列。フィールド、列の 1 つだけが必要です。

Optional attributes:

オプションの属性:

  • options: Array of platform specific options:

    options: プラットフォーム固有のオプションの配列:

    • where: SQL WHERE condition to be used for partial indexes. It will only have effect on supported platforms.

      where: 部分インデックスに使用する SQL WHERE 条件。サポートされているプラ​​ットフォームでのみ効果があります。

Basic example:

基本的な例:

<?php
/**
 * @Entity
 * @Table(name="ecommerce_products",uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "email"})})
 */
class ECommerceProduct
{
}

Basic example using fields:

フィールドを使用した基本的な例:

<?php
/**
 * @Entity
 * @Table(name="ecommerce_products",uniqueConstraints={@UniqueConstraint(name="search_idx", fields={"name", "email"})})
 */
class ECommerceProduct
{
}

Example with partial indexes:

部分インデックスの例:

<?php
/**
 * @Entity
 * @Table(name="ecommerce_products",uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "email"}, options={"where": "(((id IS NOT NULL) AND (name IS NULL)) AND (email IS NULL))"})})
 */
class ECommerceProduct
{
}

19.2.39. @Version

Marker annotation that defines a specified column as version attribute used in an optimistic locking scenario. It only works on @Column annotations that have the type integer or datetime. Combining @Version with @Id is not supported.

オプティミスティック ロック シナリオで使用されるバージョン属性として指定された列を定義するマーカー アノテーション。整数型または日時型の @Column アノテーションでのみ機能します。 @Version と @Id の組み合わせはサポートされていません。

Example:

例:

<?php
/**
 * @Column(type="integer")
 * @Version
 */
protected $version;

Table Of Contents

Previous topic

18. Partial Objects

18. 部分オブジェクト

Next topic

20. Attributes Reference

20. 属性リファレンス

This Page

Fork me on GitHub