diff --git a/en/reference/association-mapping.rst b/en/reference/association-mapping.rst index 869fc1235..5a8c58855 100644 --- a/en/reference/association-mapping.rst +++ b/en/reference/association-mapping.rst @@ -601,35 +601,71 @@ the join columns enforces the one-to-many cardinality. The following example sets up such a unidirectional one-to-many association: -.. code-block:: php +.. code-configuration:: - phonenumbers = new \Doctrine\Common\Collections\ArrayCollection(); + .. code-block:: php + + phonenumbers = new \Doctrine\Common\Collections\ArrayCollection(); + } + + // ... } - - // ... - } - - /** @Entity */ - class Phonenumber - { - // ... - } + + /** @Entity */ + class Phonenumber + { + // ... + } + + .. code-block:: xml + + + + + + + + + + + + + + + + + .. code-block:: yaml + + User: + type: entity + manyToMany: + phonenumbers: + targetEntity: Phonenumber + joinTable: + name: users_phonenumbers + joinColumns: + user_id: + referencedColumnName: id + inverseJoinColumns + phonenumber_id: + referencedColumnName: id + unique: true .. note:: @@ -667,26 +703,45 @@ Many-To-One, Unidirectional You can easily implement a many-to-one unidirectional association with the following: -.. code-block:: php +.. configuration-block:: + + .. code-block:: php + + + + + + + + .. code-block:: yaml + + User: + type: entity + manyToOne: + address: + targetEntity: Address - features = new \Doctrine\Common\Collections\ArrayCollection(); + .. code-block:: php + + features = new \Doctrine\Common\Collections\ArrayCollection(); + } } - } - - /** @Entity */ - class Feature - { - // ... - /** - * @ManyToOne(targetEntity="Product", inversedBy="features") - * @JoinColumn(name="product_id", referencedColumnName="id") - */ - private $product; - // ... - } + + /** @Entity */ + class Feature + { + // ... + /** + * @ManyToOne(targetEntity="Product", inversedBy="features") + * @JoinColumn(name="product_id", referencedColumnName="id") + */ + private $product; + // ... + } + + .. code-block:: xml + + + + + + + + + + + Note that the @JoinColumn is not really necessary in this example, as the defaults would be the same. @@ -776,29 +846,53 @@ self-referencing. In this example we setup a hierarchy of This effectively models a hierarchy of categories and from the database perspective is known as an adjacency list approach. -.. code-block:: php +.. configuration-block:: - children = new \Doctrine\Common\Collections\ArrayCollection(); + .. code-block:: php + + children = new \Doctrine\Common\Collections\ArrayCollection(); + } } - } + + .. code-block:: xml + + + + + + + + + .. code-block:: yaml + + Category: + type: entity + oneToMany: + children + targetEntity: Category + mappedBy: parent + manyToOne: + parent: + targetEntity: Category + inversedBy: children Note that the @JoinColumn is not really necessary in this example, as the defaults would be the same. diff --git a/en/reference/basic-mapping.rst b/en/reference/basic-mapping.rst index 0a00ee702..a1c17f621 100644 --- a/en/reference/basic-mapping.rst +++ b/en/reference/basic-mapping.rst @@ -567,7 +567,7 @@ besides specifying the sequence's name: - + .. code-block:: yaml MyPersistentClass: