From 718ee42e8ed03712df40bcf05f1c27e0ec6b2f41 Mon Sep 17 00:00:00 2001 From: Michal-sk Date: Thu, 21 Jul 2016 07:39:07 +0200 Subject: [PATCH 1/2] Update association-mapping.rst Added pointers on how to interpret the method names. This helped me to quicker grasp the concept of the Relations and there methods. Added a @var annotation to the `Collection` interface to make it clear that the `$groups` is a child of the `Collection` interface. --- docs/en/reference/association-mapping.rst | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index a1a9f83a8..d2b2cced7 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -16,6 +16,8 @@ This chapter is split into three different sections. - :ref:`association_mapping_defaults` are explained that simplify the use-case examples. - :ref:`collections` are introduced that contain entities in associations. +One tip for working with relations is to read the relation from left to right, where the left word referece to the current class. + To gain a full understanding of associations you should also read about :doc:`owning and inverse sides of associations ` @@ -35,6 +37,7 @@ A many-to-one association is the most common association between objects. // ... /** + * Many Users have One Address. * @ManyToOne(targetEntity="Address") * @JoinColumn(name="address_id", referencedColumnName="id") */ @@ -111,6 +114,7 @@ direction only. // ... /** + * One Product has One Shipping. * @OneToOne(targetEntity="Shipping") * @JoinColumn(name="shipping_id", referencedColumnName="id") */ @@ -183,6 +187,7 @@ it is bidirectional. // ... /** + * One Customer has One Cart. * @OneToOne(targetEntity="Cart", mappedBy="customer") */ private $cart; @@ -196,6 +201,7 @@ it is bidirectional. // ... /** + * One Cart has One Customer. * @OneToOne(targetEntity="Customer", inversedBy="cart") * @JoinColumn(name="customer_id", referencedColumnName="id") */ @@ -269,6 +275,7 @@ below. // ... /** + * One Student has One Student. * @OneToOne(targetEntity="Student") * @JoinColumn(name="mentor_id", referencedColumnName="id") */ @@ -316,6 +323,7 @@ association. { // ... /** + * One Product has Many Features. * @OneToMany(targetEntity="Feature", mappedBy="product") */ private $features; @@ -331,6 +339,7 @@ association. { // ... /** + * Many Features have One Product. * @ManyToOne(targetEntity="Product", inversedBy="features") * @JoinColumn(name="product_id", referencedColumnName="id") */ @@ -408,6 +417,7 @@ The following example sets up such a unidirectional one-to-many association: // ... /** + * Many User have Many Phonenumbers. * @ManyToMany(targetEntity="Phonenumber") * @JoinTable(name="users_phonenumbers", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, @@ -508,11 +518,13 @@ database perspective is known as an adjacency list approach. { // ... /** + * One Category has Many Categories. * @OneToMany(targetEntity="Category", mappedBy="parent") */ private $children; /** + * Many Categories have One Category. * @ManyToOne(targetEntity="Category", inversedBy="children") * @JoinColumn(name="parent_id", referencedColumnName="id") */ @@ -578,6 +590,7 @@ entities: // ... /** + * Many Users have Many Groups. * @ManyToMany(targetEntity="Group") * @JoinTable(name="users_groups", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, @@ -678,6 +691,7 @@ one is bidirectional. // ... /** + * Many Users have Many Groups. * @ManyToMany(targetEntity="Group", inversedBy="users") * @JoinTable(name="users_groups") */ @@ -695,6 +709,7 @@ one is bidirectional. { // ... /** + * Many Groups have Many Users. * @ManyToMany(targetEntity="User", mappedBy="groups") */ private $users; @@ -825,11 +840,13 @@ field named ``$friendsWithMe`` and ``$myFriends``. // ... /** + * Many Users have Many Users. * @ManyToMany(targetEntity="User", mappedBy="myFriends") */ private $friendsWithMe; /** + * Many Users have many Users. * @ManyToMany(targetEntity="User", inversedBy="friendsWithMe") * @JoinTable(name="friends", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, @@ -911,6 +928,7 @@ mapping: Date: Thu, 21 Jul 2016 13:41:21 +0200 Subject: [PATCH 2/2] Update association-mapping.rst Added spoken word examples of the relationship methods --- docs/en/reference/association-mapping.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index d2b2cced7..1b58baa0d 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -16,7 +16,13 @@ This chapter is split into three different sections. - :ref:`association_mapping_defaults` are explained that simplify the use-case examples. - :ref:`collections` are introduced that contain entities in associations. -One tip for working with relations is to read the relation from left to right, where the left word referece to the current class. +One tip for working with relations is to read the relation from left to right, where the left word refers to the current Entity. For example: + +- OneToMany - One instance of the current Entity has Many instances (references) to the refered Entity. +- ManyToOne - Many instances of the current Entity refer to One instance of the refered Entity. +- OneToOne - One instance of the current Entity refers to One instance of the refered Entity. + +See below for all the possible relations. To gain a full understanding of associations you should also read about :doc:`owning and inverse sides of associations `