Skip to content

Commit

Permalink
Migrate documentation to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Oct 15, 2022
1 parent 7ce9a6f commit e762952
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
52 changes: 27 additions & 25 deletions docs/en/reference/working-with-associations.rst
Expand Up @@ -32,62 +32,64 @@ information about its type and if it's the owning or inverse side.
.. code-block:: php
<?php
/** @Entity */
#[Entity]
class User
{
/** @Id @GeneratedValue @Column(type="string") */
private $id;
#[Id, GeneratedValue, Column(type: 'integer')]
private int|null $id;
/**
* Bidirectional - Many users have Many favorite comments (OWNING SIDE)
*
* @ManyToMany(targetEntity="Comment", inversedBy="userFavorites")
* @JoinTable(name="user_favorite_comments")
* @var Collection<int, Comment>
*/
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<int, Comment>
*/
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<int, Comment>
*/
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<int, User>
*/
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
Expand Down
25 changes: 10 additions & 15 deletions docs/en/tutorials/composite-primary-keys.rst
Expand Up @@ -23,33 +23,28 @@ and year of production as primary keys:

.. configuration-block::

.. code-block:: php
.. code-block:: attribute
<?php
namespace VehicleCatalogue\Model;
/**
* @Entity
*/
#[Entity]
class Car
{
/** @Id @Column(type="string") */
private $name;
/** @Id @Column(type="integer") */
private $year;
public function __construct($name, $year)
{
$this->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;
}
Expand Down

0 comments on commit e762952

Please sign in to comment.