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