@@ -32,62 +32,64 @@ information about its type and if it's the owning or inverse side.
32
32
.. code-block :: php
33
33
34
34
<?php
35
- /** @ Entity */
35
+ #[ Entity]
36
36
class User
37
37
{
38
- /** @Id @ GeneratedValue @ Column(type="string") */
39
- private $id;
38
+ #[Id, GeneratedValue, Column(type: 'integer')]
39
+ private int|null $id;
40
40
41
41
/**
42
42
* Bidirectional - Many users have Many favorite comments (OWNING SIDE)
43
43
*
44
- * @ManyToMany(targetEntity="Comment", inversedBy="userFavorites")
45
- * @JoinTable(name="user_favorite_comments")
44
+ * @var Collection<int , Comment >
46
45
*/
47
- private $favorites;
46
+ #[ManyToMany(targetEntity: Comment::class, inversedBy: 'userFavorites')]
47
+ #[JoinTable(name: 'user_favorite_comments')]
48
+ private Collection $favorites;
48
49
49
50
/**
50
51
* Unidirectional - Many users have marked many comments as read
51
52
*
52
- * @ManyToMany(targetEntity="Comment")
53
- * @JoinTable(name="user_read_comments")
53
+ * @var Collection<int , Comment >
54
54
*/
55
- private $commentsRead;
55
+ #[ManyToMany(targetEntity: Comment::class)]
56
+ #[JoinTable(name: 'user_read_comments')]
57
+ private Collection $commentsRead;
56
58
57
59
/**
58
60
* Bidirectional - One-To-Many (INVERSE SIDE)
59
61
*
60
- * @OneToMany(targetEntity="Comment", mappedBy="author")
62
+ * @var Collection< int , Comment >
61
63
*/
62
- private $commentsAuthored;
64
+ #[OneToMany(targetEntity: Comment::class, mappedBy: 'author')]
65
+ private Collection $commentsAuthored;
63
66
64
- /**
65
- * Unidirectional - Many-To-One
66
- *
67
- * @ManyToOne(targetEntity="Comment")
68
- */
69
- private $firstComment;
67
+ /** Unidirectional - Many-To-One */
68
+ #[ManyToOne(targetEntity: Comment::class)]
69
+ private Comment|null $firstComment;
70
70
}
71
71
72
- /** @ Entity */
72
+ #[ Entity]
73
73
class Comment
74
74
{
75
- /** @Id @GeneratedValue @Column(type="string") */
76
- private $id;
75
+ #[Id]
76
+ #[GeneratedValue]
77
+ #[Column(type: 'string')]
78
+ private string $id;
77
79
78
80
/**
79
81
* Bidirectional - Many comments are favorited by many users (INVERSE SIDE)
80
82
*
81
- * @ManyToMany(targetEntity="User", mappedBy="favorites")
83
+ * @var Collection< int , User >
82
84
*/
83
- private $userFavorites;
85
+ #[ManyToMany(targetEntity: User::class, mappedBy: 'favorites')]
86
+ private Collection $userFavorites;
84
87
85
88
/**
86
89
* Bidirectional - Many Comments are authored by one user (OWNING SIDE)
87
- *
88
- * @ManyToOne(targetEntity="User", inversedBy="commentsAuthored")
89
90
*/
90
- private $author;
91
+ #[ManyToOne(targetEntity: User::class, inversedBy: 'commentsAuthored')]
92
+ private User|null $author;
91
93
}
92
94
93
95
This two entities generate the following MySQL Schema (Foreign Key
0 commit comments