Skip to content

Commit 0852847

Browse files
Docs: Moving *attributes* mapping to first position (#10364)
1 parent 1e2625a commit 0852847

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

docs/en/tutorials/composite-primary-keys.rst

+32-32
Original file line numberDiff line numberDiff line change
@@ -169,95 +169,95 @@ We keep up the example of an Article with arbitrary attributes, the mapping look
169169

170170
.. configuration-block::
171171

172-
.. code-block:: php
172+
.. code-block:: attribute
173173
174174
<?php
175175
namespace Application\Model;
176176
177177
use Doctrine\Common\Collections\ArrayCollection;
178178
179-
/**
180-
* @Entity
181-
*/
179+
#[Entity]
182180
class Article
183181
{
184-
/** @Id @Column(type="integer") @GeneratedValue */
182+
#[Id, Column(type: 'integer'), GeneratedValue]
185183
private int|null $id = null;
186-
/** @Column(type="string") */
184+
#[Column(type: 'string')]
187185
private string $title;
188186
189-
/**
190-
* @OneToMany(targetEntity="ArticleAttribute", mappedBy="article", cascade={"ALL"}, indexBy="attribute")
191-
* @var Collection<int, ArticleAttribute>
192-
*/
187+
/** @var ArrayCollection<string, ArticleAttribute> */
188+
#[OneToMany(targetEntity: ArticleAttribute::class, mappedBy: 'article', cascade: ['ALL'], indexBy: 'attribute')]
193189
private Collection $attributes;
194190
195-
public function addAttribute($name, $value): void
191+
public function addAttribute(string $name, ArticleAttribute $value): void
196192
{
197193
$this->attributes[$name] = new ArticleAttribute($name, $value, $this);
198194
}
199195
}
200196
201-
/**
202-
* @Entity
203-
*/
197+
#[Entity]
204198
class ArticleAttribute
205199
{
206-
/** @Id @ManyToOne(targetEntity="Article", inversedBy="attributes") */
207-
private Article|null $article;
200+
#[Id, ManyToOne(targetEntity: Article::class, inversedBy: 'attributes')]
201+
private Article $article;
208202
209-
/** @Id @Column(type="string") */
203+
#[Id, Column(type: 'string')]
210204
private string $attribute;
211205
212-
/** @Column(type="string") */
206+
#[Column(type: 'string')]
213207
private string $value;
214208
215-
public function __construct($name, $value, $article)
209+
public function __construct(string $name, string $value, Article $article)
216210
{
217211
$this->attribute = $name;
218212
$this->value = $value;
219213
$this->article = $article;
220214
}
221215
}
222216
223-
.. code-block:: attribute
217+
.. code-block:: annotation
224218
225219
<?php
226220
namespace Application\Model;
227221
228222
use Doctrine\Common\Collections\ArrayCollection;
229223
230-
#[Entity]
224+
/**
225+
* @Entity
226+
*/
231227
class Article
232228
{
233-
#[Id, Column(type: 'integer'), GeneratedValue]
229+
/** @Id @Column(type="integer") @GeneratedValue */
234230
private int|null $id = null;
235-
#[Column(type: 'string')]
231+
/** @Column(type="string") */
236232
private string $title;
237233
238-
/** @var ArrayCollection<string, ArticleAttribute> */
239-
#[OneToMany(targetEntity: ArticleAttribute::class, mappedBy: 'article', cascade: ['ALL'], indexBy: 'attribute')]
234+
/**
235+
* @OneToMany(targetEntity="ArticleAttribute", mappedBy="article", cascade={"ALL"}, indexBy="attribute")
236+
* @var Collection<int, ArticleAttribute>
237+
*/
240238
private Collection $attributes;
241239
242-
public function addAttribute(string $name, ArticleAttribute $value): void
240+
public function addAttribute($name, $value): void
243241
{
244242
$this->attributes[$name] = new ArticleAttribute($name, $value, $this);
245243
}
246244
}
247245
248-
#[Entity]
246+
/**
247+
* @Entity
248+
*/
249249
class ArticleAttribute
250250
{
251-
#[Id, ManyToOne(targetEntity: Article::class, inversedBy: 'attributes')]
252-
private Article $article;
251+
/** @Id @ManyToOne(targetEntity="Article", inversedBy="attributes") */
252+
private Article|null $article;
253253
254-
#[Id, Column(type: 'string')]
254+
/** @Id @Column(type="string") */
255255
private string $attribute;
256256
257-
#[Column(type: 'string')]
257+
/** @Column(type="string") */
258258
private string $value;
259259
260-
public function __construct(string $name, string $value, Article $article)
260+
public function __construct($name, $value, $article)
261261
{
262262
$this->attribute = $name;
263263
$this->value = $value;

0 commit comments

Comments
 (0)