@@ -140,34 +140,6 @@ the ``Product`` entity (and getter & setter methods):
140140
141141.. configuration-block ::
142142
143- .. code-block :: php-annotations
144-
145- // src/Entity/Product.php
146- namespace App\Entity;
147-
148- // ...
149- class Product
150- {
151- // ...
152-
153- /**
154- * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="products")
155- */
156- private $category;
157-
158- public function getCategory(): ?Category
159- {
160- return $this->category;
161- }
162-
163- public function setCategory(?Category $category): self
164- {
165- $this->category = $category;
166-
167- return $this;
168- }
169- }
170-
171143 .. code-block :: php-attributes
172144
173145 // src/Entity/Product.php
@@ -178,7 +150,7 @@ the ``Product`` entity (and getter & setter methods):
178150 {
179151 // ...
180152
181- #[ORM\ManyToOne(targetEntity: Category::class, inversedBy: " products" )]
153+ #[ORM\ManyToOne(targetEntity: Category::class, inversedBy: ' products' )]
182154 private $category;
183155
184156 public function getCategory(): ?Category
@@ -237,40 +209,6 @@ class that will hold these objects:
237209
238210.. configuration-block ::
239211
240- .. code-block :: php-annotations
241-
242- // src/Entity/Category.php
243- namespace App\Entity;
244-
245- // ...
246- use Doctrine\Common\Collections\ArrayCollection;
247- use Doctrine\Common\Collections\Collection;
248-
249- class Category
250- {
251- // ...
252-
253- /**
254- * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="category")
255- */
256- private $products;
257-
258- public function __construct()
259- {
260- $this->products = new ArrayCollection();
261- }
262-
263- /**
264- * @return Collection|Product[]
265- */
266- public function getProducts(): Collection
267- {
268- return $this->products;
269- }
270-
271- // addProduct() and removeProduct() were also added
272- }
273-
274212 .. code-block :: php-attributes
275213
276214 // src/Entity/Category.php
@@ -284,7 +222,7 @@ class that will hold these objects:
284222 {
285223 // ...
286224
287- #[ORM\OneToMany(targetEntity: Product::class, mappedBy: " category" )]
225+ #[ORM\OneToMany(targetEntity: Product::class, mappedBy: ' category' )]
288226 private $products;
289227
290228 public function __construct()
@@ -647,24 +585,13 @@ that behavior, use the `orphanRemoval`_ option inside ``Category``:
647585
648586.. configuration-block ::
649587
650- .. code-block :: php-annotations
651-
652- // src/Entity/Category.php
653-
654- // ...
655-
656- /**
657- * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="category", orphanRemoval=true)
658- */
659- private $products;
660-
661588 .. code-block :: php-attributes
662589
663590 // src/Entity/Category.php
664591
665592 // ...
666593
667- #[ORM\OneToMany(targetEntity: Product::class, mappedBy: " category" , orphanRemoval: true)]
594+ #[ORM\OneToMany(targetEntity: Product::class, mappedBy: ' category' , orphanRemoval: true)]
668595 private $products;
669596
670597
@@ -681,8 +608,8 @@ Doctrine's `Association Mapping Documentation`_.
681608
682609.. note ::
683610
684- If you're using annotations , you'll need to prepend all annotations with
685- ``@ ORM\ `` (e.g. ``@ ORM\OneToMany ``), which is not reflected in Doctrine's
611+ If you're using attributes , you'll need to prepend all attributes with
612+ ``#[ ORM\] `` (e.g. ``#[ ORM\OneToMany] ``), which is not reflected in Doctrine's
686613 documentation.
687614
688615.. _`Association Mapping Documentation` : https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/association-mapping.html
0 commit comments