diff --git a/en/reference/association-mapping.rst b/en/reference/association-mapping.rst index a8e6690b6..72feecc9d 100644 --- a/en/reference/association-mapping.rst +++ b/en/reference/association-mapping.rst @@ -915,35 +915,70 @@ Real many-to-many associations are less common. The following example shows a unidirectional association between User and Group entities: -.. code-block:: php +.. configuration-block:: - groups = new \Doctrine\Common\Collections\ArrayCollection(); + .. code-block:: php + + groups = new \Doctrine\Common\Collections\ArrayCollection(); + } } - } - - /** @Entity */ - class Group - { - // ... - } + + /** @Entity */ + class Group + { + // ... + } + + .. code-block:: xml + + + + + + + + + + + + + + + + + .. code-block:: yaml + + User: + type: entity + manyToMany: + groups: + targetEntity: Group + joinTable: + name: users_groups + joinColumns: + user_id: + referencedColumnName: id + inverseJoinColumns: + group_id: + referencedColumnName: id Generated MySQL Schema: @@ -980,45 +1015,89 @@ Many-To-Many, Bidirectional Here is a similar many-to-many relationship as above except this one is bidirectional. -.. code-block:: php +.. configuration-block:: - groups = new \Doctrine\Common\Collections\ArrayCollection(); + .. code-block:: php + + groups = new \Doctrine\Common\Collections\ArrayCollection(); + } + + // ... } - - // ... - } - - /** @Entity */ - class Group - { - // ... - /** - * @ManyToMany(targetEntity="User", mappedBy="groups") - */ - private $users; - - public function __construct() { - $this->users = new \Doctrine\Common\Collections\ArrayCollection(); + + /** @Entity */ + class Group + { + // ... + /** + * @ManyToMany(targetEntity="User", mappedBy="groups") + */ + private $users; + + public function __construct() { + $this->users = new \Doctrine\Common\Collections\ArrayCollection(); + } + + // ... } - - // ... - } + + .. code-block:: + + + + + + + + + + + + + + + + + + + + + .. code-block:: + + User: + type: entity + manyToMany: + groups: + targetEntity: Group + inversedBy: users + joinTable: + name: users_groups + joinColumns: + user_id: + referencedColumnName: id + inverseJoinColumns: + group_id: + referencedColumnName: id + + Group: + type: entity + manyToMany: + users: + targetEntity: User + mappedBy: groups The MySQL schema is exactly the same as for the Many-To-Many uni-directional case above.