@@ -140,34 +140,6 @@ the ``Product`` entity (and getter & setter methods):
140
140
141
141
.. configuration-block ::
142
142
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
-
171
143
.. code-block :: php-attributes
172
144
173
145
// src/Entity/Product.php
@@ -178,7 +150,7 @@ the ``Product`` entity (and getter & setter methods):
178
150
{
179
151
// ...
180
152
181
- #[ORM\ManyToOne(targetEntity: Category::class, inversedBy: " products" )]
153
+ #[ORM\ManyToOne(targetEntity: Category::class, inversedBy: ' products' )]
182
154
private $category;
183
155
184
156
public function getCategory(): ?Category
@@ -237,40 +209,6 @@ class that will hold these objects:
237
209
238
210
.. configuration-block ::
239
211
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
-
274
212
.. code-block :: php-attributes
275
213
276
214
// src/Entity/Category.php
@@ -284,7 +222,7 @@ class that will hold these objects:
284
222
{
285
223
// ...
286
224
287
- #[ORM\OneToMany(targetEntity: Product::class, mappedBy: " category" )]
225
+ #[ORM\OneToMany(targetEntity: Product::class, mappedBy: ' category' )]
288
226
private $products;
289
227
290
228
public function __construct()
@@ -647,24 +585,13 @@ that behavior, use the `orphanRemoval`_ option inside ``Category``:
647
585
648
586
.. configuration-block ::
649
587
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
-
661
588
.. code-block :: php-attributes
662
589
663
590
// src/Entity/Category.php
664
591
665
592
// ...
666
593
667
- #[ORM\OneToMany(targetEntity: Product::class, mappedBy: " category" , orphanRemoval: true)]
594
+ #[ORM\OneToMany(targetEntity: Product::class, mappedBy: ' category' , orphanRemoval: true)]
668
595
private $products;
669
596
670
597
@@ -681,8 +608,8 @@ Doctrine's `Association Mapping Documentation`_.
681
608
682
609
.. note ::
683
610
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
686
613
documentation.
687
614
688
615
.. _`Association Mapping Documentation` : https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/association-mapping.html
0 commit comments