11. Association Updates: Owning Side and Inverse Side

When mapping bidirectional associations it is important to understand the concept of the owning and inverse sides. The following general rules apply:

双方向の関連付けをマッピングする場合、所有側と逆側の概念を理解することが重要です。次の一般規則が適用されます。

  • Relationships may be bidirectional or unidirectional.

    関係は、双方向または単方向の場合があります。

  • A bidirectional relationship has both an owning side and an inverse side

    双方向の関係には、所有側と逆側の両方があります

  • A unidirectional relationship only has an owning side.

    一方向の関係には、所有側しかありません。

  • Doctrine will only check the owning side of an association for changes.

    Doctrine は関連付けの所有側の変更のみをチェックします。

11.1. Bidirectional Associations

The following rules apply to bidirectional associations:

双方向の関連付けには、次の規則が適用されます。

  • The inverse side has to have the mappedBy attribute of the OneToOne, OneToMany, or ManyToMany mapping declaration. The mappedBy attribute contains the name of the association-field on the owning side.

    逆側には、OneToOne、OneToMany、または ManyToMany マッピング宣言の mappingBy 属性が必要です。 mappingByattribute には、所有側の関連付けフィールドの名前が含まれています。

  • The owning side has to have the inversedBy attribute of the OneToOne, ManyToOne, or ManyToMany mapping declaration. The inversedBy attribute contains the name of the association-field on the inverse-side.

    所有側には、OneToOne、ManyToOne、または ManyToMany マッピング宣言の inversedBy 属性が必要です。inversedBy 属性には、逆側の関連付けフィールドの名前が含まれます。

  • ManyToOne is always the owning side of a bidirectional association.

    ManyToOne は、常に双方向の関連付けの所有側です。

  • OneToMany is always the inverse side of a bidirectional association.

    OneToMany は、常に双方向関連の逆側です。

  • The owning side of a OneToOne association is the entity with the table containing the foreign key.

    OneToOne アソシエーションの所有側は、外部キーを含むテーブルを持つエンティティです。

  • You can pick the owning side of a many-to-many association yourself.

    多対多関連付けの所有側を自分で選択できます。

11.2. Important concepts

Doctrine will only check the owning side of an association for changes.

Doctrine は関連付けの所有側の変更のみをチェックします。

To fully understand this, remember how bidirectional associations are maintained in the object world. There are 2 references on each side of the association and these 2 references both represent the same association but can change independently of one another. Of course, in a correct application the semantics of the bidirectional association are properly maintained by the application developer (that’s their responsibility). Doctrine needs to know which of these two in-memory references is the one that should be persisted and which not. This is what the owning/inverse concept is mainly used for.

これを完全に理解するには、双方向の関連付けがオブジェクトの世界でどのように維持されるかを思い出してください。関連付けの両側に 2 つの参照があり、これら 2 つの参照は両方とも同じ関連付けを表しますが、互いに独立して変更できます。もちろん、正しいアプリケーションでは、双方向関連のセマンティクスはアプリケーション開発者によって適切に維持されます (それは開発者の責任です)。 Doctrine は、これら 2 つのメモリ内参照のどちらが永続化されるべきものであり、どちらが永続化されるべきでないのかを知る必要があります。これは、所有/逆の概念が主に使用されるものです。

Changes made only to the inverse side of an association are ignored. Make sure to update both sides of a bidirectional association (or at least the owning side, from Doctrine’s point of view)

関連の逆側のみに加えられた変更は無視されます。双方向の関連付けの両側 (または、Doctrine の観点からは、少なくとも所有側) を更新してください。

The owning side of a bidirectional association is the side Doctrine “looks at” when determining the state of the association, and consequently whether there is anything to do to update the association in the database.

双方向アソシエーションの所有側は、アソシエーションの状態を決定する際に Doctrine が「見る」側であり、その結果、データベース内のアソシエーションを更新するために何かする必要があるかどうかを判断します。

Note

ノート

“Owning side” and “inverse side” are technical concepts of the ORM technology, not concepts of your domain model. What you consider as the owning side in your domain model can be different from what the owning side is for Doctrine. These are unrelated.

「所有側」と「逆側」は、ORM テクノロジの技術的な概念であり、ドメイン モデルの概念ではありません。ドメイン モデルで所有側と見なすものは、Doctrine の所有側とは異なる場合があります。これらは無関係です。

Table Of Contents

Previous topic

10. Doctrine Internals explained

10. Doctrine Internals の説明

Next topic

12. Transactions and Concurrency

12. トランザクションと並行性

This Page

Fork me on GitHub