Skip to content

Commit

Permalink
Docs: Moving *attributes* mapping to first position (#10364)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLandauer authored Jan 3, 2023
1 parent 1e2625a commit 0852847
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions docs/en/tutorials/composite-primary-keys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,95 +169,95 @@ We keep up the example of an Article with arbitrary attributes, the mapping look

.. configuration-block::

.. code-block:: php
.. code-block:: attribute
<?php
namespace Application\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
*/
#[Entity]
class Article
{
/** @Id @Column(type="integer") @GeneratedValue */
#[Id, Column(type: 'integer'), GeneratedValue]
private int|null $id = null;
/** @Column(type="string") */
#[Column(type: 'string')]
private string $title;
/**
* @OneToMany(targetEntity="ArticleAttribute", mappedBy="article", cascade={"ALL"}, indexBy="attribute")
* @var Collection<int, ArticleAttribute>
*/
/** @var ArrayCollection<string, ArticleAttribute> */
#[OneToMany(targetEntity: ArticleAttribute::class, mappedBy: 'article', cascade: ['ALL'], indexBy: 'attribute')]
private Collection $attributes;
public function addAttribute($name, $value): void
public function addAttribute(string $name, ArticleAttribute $value): void
{
$this->attributes[$name] = new ArticleAttribute($name, $value, $this);
}
}
/**
* @Entity
*/
#[Entity]
class ArticleAttribute
{
/** @Id @ManyToOne(targetEntity="Article", inversedBy="attributes") */
private Article|null $article;
#[Id, ManyToOne(targetEntity: Article::class, inversedBy: 'attributes')]
private Article $article;
/** @Id @Column(type="string") */
#[Id, Column(type: 'string')]
private string $attribute;
/** @Column(type="string") */
#[Column(type: 'string')]
private string $value;
public function __construct($name, $value, $article)
public function __construct(string $name, string $value, Article $article)
{
$this->attribute = $name;
$this->value = $value;
$this->article = $article;
}
}
.. code-block:: attribute
.. code-block:: annotation
<?php
namespace Application\Model;
use Doctrine\Common\Collections\ArrayCollection;
#[Entity]
/**
* @Entity
*/
class Article
{
#[Id, Column(type: 'integer'), GeneratedValue]
/** @Id @Column(type="integer") @GeneratedValue */
private int|null $id = null;
#[Column(type: 'string')]
/** @Column(type="string") */
private string $title;
/** @var ArrayCollection<string, ArticleAttribute> */
#[OneToMany(targetEntity: ArticleAttribute::class, mappedBy: 'article', cascade: ['ALL'], indexBy: 'attribute')]
/**
* @OneToMany(targetEntity="ArticleAttribute", mappedBy="article", cascade={"ALL"}, indexBy="attribute")
* @var Collection<int, ArticleAttribute>
*/
private Collection $attributes;
public function addAttribute(string $name, ArticleAttribute $value): void
public function addAttribute($name, $value): void
{
$this->attributes[$name] = new ArticleAttribute($name, $value, $this);
}
}
#[Entity]
/**
* @Entity
*/
class ArticleAttribute
{
#[Id, ManyToOne(targetEntity: Article::class, inversedBy: 'attributes')]
private Article $article;
/** @Id @ManyToOne(targetEntity="Article", inversedBy="attributes") */
private Article|null $article;
#[Id, Column(type: 'string')]
/** @Id @Column(type="string") */
private string $attribute;
#[Column(type: 'string')]
/** @Column(type="string") */
private string $value;
public function __construct(string $name, string $value, Article $article)
public function __construct($name, $value, $article)
{
$this->attribute = $name;
$this->value = $value;
Expand Down

0 comments on commit 0852847

Please sign in to comment.