From e7629524352089f46e13e37f8c064d419bbccbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 12 Oct 2022 21:18:59 +0200 Subject: [PATCH] Migrate documentation to attributes --- .../reference/working-with-associations.rst | 52 ++++++++++--------- docs/en/tutorials/composite-primary-keys.rst | 25 ++++----- 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 510d85f05b3..71721ba66b4 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -32,62 +32,64 @@ information about its type and if it's the owning or inverse side. .. code-block:: php */ - private $favorites; + #[ManyToMany(targetEntity: Comment::class, inversedBy: 'userFavorites')] + #[JoinTable(name: 'user_favorite_comments')] + private Collection $favorites; /** * Unidirectional - Many users have marked many comments as read * - * @ManyToMany(targetEntity="Comment") - * @JoinTable(name="user_read_comments") + * @var Collection */ - private $commentsRead; + #[ManyToMany(targetEntity: Comment::class)] + #[JoinTable(name: 'user_read_comments')] + private Collection $commentsRead; /** * Bidirectional - One-To-Many (INVERSE SIDE) * - * @OneToMany(targetEntity="Comment", mappedBy="author") + * @var Collection */ - private $commentsAuthored; + #[OneToMany(targetEntity: Comment::class, mappedBy: 'author')] + private Collection $commentsAuthored; - /** - * Unidirectional - Many-To-One - * - * @ManyToOne(targetEntity="Comment") - */ - private $firstComment; + /** Unidirectional - Many-To-One */ + #[ManyToOne(targetEntity: Comment::class)] + private Comment|null $firstComment; } - /** @Entity */ + #[Entity] class Comment { - /** @Id @GeneratedValue @Column(type="string") */ - private $id; + #[Id] + #[GeneratedValue] + #[Column(type: 'string')] + private string $id; /** * Bidirectional - Many comments are favorited by many users (INVERSE SIDE) * - * @ManyToMany(targetEntity="User", mappedBy="favorites") + * @var Collection */ - private $userFavorites; + #[ManyToMany(targetEntity: User::class, mappedBy: 'favorites')] + private Collection $userFavorites; /** * Bidirectional - Many Comments are authored by one user (OWNING SIDE) - * - * @ManyToOne(targetEntity="User", inversedBy="commentsAuthored") */ - private $author; + #[ManyToOne(targetEntity: User::class, inversedBy: 'commentsAuthored')] + private User|null $author; } This two entities generate the following MySQL Schema (Foreign Key diff --git a/docs/en/tutorials/composite-primary-keys.rst b/docs/en/tutorials/composite-primary-keys.rst index 12ad55e53bb..9aaae10c06a 100644 --- a/docs/en/tutorials/composite-primary-keys.rst +++ b/docs/en/tutorials/composite-primary-keys.rst @@ -23,33 +23,28 @@ and year of production as primary keys: .. configuration-block:: - .. code-block:: php + .. code-block:: attribute name = $name; - $this->year = $year; + public function __construct( + #[Id, Column(type="string")] + string $name, + #[Id, Column(type="integer")] + int $year, + ) { } - public function getModelName() + public function getModelName(): string { return $this->name; } - public function getYearOfProduction() + public function getYearOfProduction(): int { return $this->year; }