From e97c1f3f44b502ca615f6076ac4d6010ea088fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 19 Oct 2022 21:10:55 +0200 Subject: [PATCH] Restore annotations blocks They are not officially deprecated yet, and even then, can be useful documentation. --- docs/en/reference/association-mapping.rst | 339 +++++++++++++++++- docs/en/reference/basic-mapping.rst | 28 ++ docs/en/reference/events.rst | 37 +- docs/en/reference/inheritance-mapping.rst | 127 ++++++- docs/en/reference/second-level-cache.rst | 66 +++- .../transactions-and-concurrency.rst | 26 +- docs/en/tutorials/composite-primary-keys.rst | 106 +++++- docs/en/tutorials/embeddables.rst | 57 ++- docs/en/tutorials/extra-lazy-associations.rst | 19 +- docs/en/tutorials/getting-started.rst | 144 +++++++- docs/en/tutorials/ordered-associations.rst | 16 + .../working-with-indexed-associations.rst | 113 +++++- 12 files changed, 1043 insertions(+), 35 deletions(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index fd760866e15..9b1257f411e 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -37,7 +37,28 @@ A many-to-one association is the most common association between objects. Exampl .. configuration-block:: - .. code-block:: php + .. code-block:: annotation + + + * @OneToMany(targetEntity="Feature", mappedBy="product") + */ + private Collection $features; + // ... + + public function __construct() { + $this->features = new ArrayCollection(); + } + } + + /** @Entity */ + class Feature + { + // ... + /** + * Many features have one product. This is the owning side. + * @ManyToOne(targetEntity="Product", inversedBy="features") + * @JoinColumn(name="product_id", referencedColumnName="id") + */ + private Product|null $product = null; + // ... + } + + .. code-block:: attribute + */ + private Collection $phonenumbers; + + public function __construct() + { + $this->phonenumbers = new \Doctrine\Common\Collections\ArrayCollection(); + } + + // ... + } + + /** @Entity */ + class Phonenumber + { + // ... + } + + .. code-block:: attribute + */ + private Collection $children; + + /** + * Many Categories have One Category. + * @ManyToOne(targetEntity="Category", inversedBy="children") + * @JoinColumn(name="parent_id", referencedColumnName="id") + */ + private Category|null $parent = null; + // ... + + public function __construct() { + $this->children = new \Doctrine\Common\Collections\ArrayCollection(); + } + } + + .. code-block:: attribute + */ + private Collection $groups; + + // ... + + public function __construct() { + $this->groups = new \Doctrine\Common\Collections\ArrayCollection(); + } + } + + /** @Entity */ + class Group + { + // ... + } + + .. code-block:: attribute + */ + private Collection $groups; + + public function __construct() { + $this->groups = new \Doctrine\Common\Collections\ArrayCollection(); + } + + // ... + } + + /** @Entity */ + class Group + { + // ... + /** + * Many Groups have Many Users. + * @ManyToMany(targetEntity="User", mappedBy="groups") + * @var Collection + */ + private Collection $users; + + public function __construct() { + $this->users = new \Doctrine\Common\Collections\ArrayCollection(); + } + + // ... + } + + .. code-block:: attribute + */ + private Collection $groups; + // ... + } + + .. code-block:: attribute + + */ #[ManyToMany(targetEntity: Group::class)] private Collection $groups; // ... @@ -995,7 +1271,26 @@ This is essentially the same as the following, more verbose, mapping: .. configuration-block:: - .. code-block:: php + .. code-block:: annotation + + + */ + private Collection $groups; + // ... + } + + .. code-block:: attribute diff --git a/docs/en/reference/inheritance-mapping.rst b/docs/en/reference/inheritance-mapping.rst index 183769a9b02..00f1a9dd461 100644 --- a/docs/en/reference/inheritance-mapping.rst +++ b/docs/en/reference/inheritance-mapping.rst @@ -97,7 +97,31 @@ Example: .. configuration-block:: - .. code-block:: php + .. code-block:: annotation + + + */ + protected Collection $groups; + + /** + * @ManyToOne(targetEntity="Address") + * @JoinColumn(name="address_id", referencedColumnName="id") + */ + protected Address|null $address = null; + } + + // admin mapping + namespace MyProject\Model; + /** + * @Entity + * @AssociationOverrides({ + * @AssociationOverride(name="groups", + * joinTable=@JoinTable( + * name="users_admingroups", + * joinColumns=@JoinColumn(name="adminuser_id"), + * inverseJoinColumns=@JoinColumn(name="admingroup_id") + * ) + * ), + * @AssociationOverride(name="address", + * joinColumns=@JoinColumn( + * name="adminaddress_id", referencedColumnName="id" + * ) + * ) + * }) + */ + class Admin extends User + { + } + + .. code-block:: attribute + */ + protected Collection $cities; + + // other properties and methods + } + + .. code-block:: attribute name = $name; + $this->year = $year; + } + + public function getModelName(): string + { + return $this->name; + } + + public function getYearOfProduction(): int + { + return $this->year; + } + } + .. code-block:: attribute + */ + private Collection $attributes; + + public function addAttribute($name, $value): void + { + $this->attributes[$name] = new ArticleAttribute($name, $value, $this); + } + } + + /** + * @Entity + */ + class ArticleAttribute + { + /** @Id @ManyToOne(targetEntity="Article", inversedBy="attributes") */ + private Article|null $article; + + /** @Id @Column(type="string") */ + private string $attribute; + + /** @Column(type="string") */ + private string $value; + + public function __construct($name, $value, $article) + { + $this->attribute = $name; + $this->value = $value; + $this->article = $article; + } + } + + .. code-block:: attribute + + + */ + public Collection $users; + } + + .. code-block:: attribute An ArrayCollection of Bug objects. + */ + private Collection $reportedBugs; + + /** + * @ORM\OneToMany(targetEntity="Bug", mappedBy="engineer") + * @var Collection An ArrayCollection of Bug objects. + */ + private Collection $assignedBugs; + + // .. (other code) + } + .. code-block:: attribute + */ + private Collection $groups; + } + .. code-block:: attribute + */ + private Collection $stocks; + + public function __construct($name) + { + $this->name = $name; + $this->stocks = new ArrayCollection(); + } + + public function getId(): int|null + { + return $this->id; + } + + public function getName(): string + { + return $this->name; + } + + public function addStock(Stock $stock): void + { + $this->stocks[$stock->getSymbol()] = $stock; + } + + public function getStock($symbol): Stock + { + if (!isset($this->stocks[$symbol])) { + throw new \InvalidArgumentException("Symbol is not traded on this market."); + } + + return $this->stocks[$symbol]; + } + + /** @return array */ + public function getStocks(): array + { + return $this->stocks->toArray(); + } + } + + .. code-block:: attribute symbol = $symbol; + $this->market = $market; + $market->addStock($this); + } + + public function getSymbol(): string + { + return $this->symbol; + } + } + + .. code-block:: attribute