@@ -32,9 +32,9 @@ and year of production as primary keys:
32
32
class Car
33
33
{
34
34
public function __construct(
35
- #[Id, Column(type: 'string') ]
35
+ #[Id, Column]
36
36
private string $name,
37
- #[Id, Column(type: 'integer') ]
37
+ #[Id, Column]
38
38
private int $year,
39
39
) {
40
40
}
@@ -89,7 +89,7 @@ And for querying you can use arrays to both DQL and EntityRepositories:
89
89
90
90
$dql = "SELECT c FROM VehicleCatalogue\Model\Car c WHERE c.id = ?1";
91
91
$audi = $em->createQuery($dql)
92
- ->setParameter(1, array( "name" => "Audi A8", "year" => 2010) )
92
+ ->setParameter(1, [ "name" => "Audi A8", "year" => 2010] )
93
93
->getSingleResult();
94
94
95
95
You can also use this entity in associations. Doctrine will then generate two foreign keys one for ``name ``
@@ -126,95 +126,95 @@ We keep up the example of an Article with arbitrary attributes, the mapping look
126
126
127
127
.. configuration-block ::
128
128
129
- .. code-block :: php
129
+ .. code-block :: attribute
130
130
131
131
<?php
132
132
namespace Application\Model;
133
133
134
134
use Doctrine\Common\Collections\ArrayCollection;
135
135
136
- /**
137
- * @Entity
138
- */
136
+ #[Entity]
139
137
class Article
140
138
{
141
- /** @Id @ Column(type="integer") @ GeneratedValue */
139
+ #[Id, Column, GeneratedValue]
142
140
private int|null $id = null;
143
- /** @ Column(type="string") */
141
+ #[ Column]
144
142
private string $title;
145
143
146
- /**
147
- * @OneToMany(targetEntity="ArticleAttribute", mappedBy="article", cascade={"ALL"}, indexBy="attribute")
148
- * @var Collection<int , ArticleAttribute >
149
- */
144
+ /** @var ArrayCollection<string, ArticleAttribute> */
145
+ #[OneToMany(targetEntity: ArticleAttribute::class, mappedBy: 'article', cascade: ['ALL'], indexBy: 'attribute')]
150
146
private Collection $attributes;
151
147
152
- public function addAttribute($name, $value): void
148
+ public function addAttribute(string $name, ArticleAttribute $value): void
153
149
{
154
150
$this->attributes[$name] = new ArticleAttribute($name, $value, $this);
155
151
}
156
152
}
157
153
158
- /**
159
- * @Entity
160
- */
154
+ #[Entity]
161
155
class ArticleAttribute
162
156
{
163
- /** @Id @ ManyToOne(targetEntity=" Article" , inversedBy=" attributes") */
164
- private Article|null $article;
157
+ #[Id, ManyToOne(targetEntity: Article::class , inversedBy: ' attributes')]
158
+ private Article $article;
165
159
166
- /** @Id @ Column(type="string") */
160
+ #[Id, Column]
167
161
private string $attribute;
168
162
169
- /** @ Column(type="string") */
163
+ #[ Column]
170
164
private string $value;
171
165
172
- public function __construct($name, $value, $article)
166
+ public function __construct(string $name, string $value, Article $article)
173
167
{
174
168
$this->attribute = $name;
175
169
$this->value = $value;
176
170
$this->article = $article;
177
171
}
178
172
}
179
173
180
- .. code-block :: attribute
174
+ .. code-block :: annotation
181
175
182
176
<?php
183
177
namespace Application\Model;
184
178
185
179
use Doctrine\Common\Collections\ArrayCollection;
186
180
187
- #[Entity]
181
+ /**
182
+ * @Entity
183
+ */
188
184
class Article
189
185
{
190
- #[Id, Column(type: ' integer'), GeneratedValue]
186
+ /** @Id @ Column(type=" integer") @ GeneratedValue */
191
187
private int|null $id = null;
192
- #[ Column(type: ' string')]
188
+ /** @ Column(type=" string") */
193
189
private string $title;
194
190
195
- /** @var ArrayCollection<string, ArticleAttribute> */
196
- #[OneToMany(targetEntity: ArticleAttribute::class, mappedBy: 'article', cascade: ['ALL'], indexBy: 'attribute')]
191
+ /**
192
+ * @OneToMany(targetEntity="ArticleAttribute", mappedBy="article", cascade={"ALL"}, indexBy="attribute")
193
+ * @var Collection<int, ArticleAttribute>
194
+ */
197
195
private Collection $attributes;
198
196
199
- public function addAttribute(string $name, ArticleAttribute $value): void
197
+ public function addAttribute($name, $value): void
200
198
{
201
199
$this->attributes[$name] = new ArticleAttribute($name, $value, $this);
202
200
}
203
201
}
204
202
205
- #[Entity]
203
+ /**
204
+ * @Entity
205
+ */
206
206
class ArticleAttribute
207
207
{
208
- #[Id, ManyToOne(targetEntity: Article::class , inversedBy: ' attributes')]
209
- private Article $article;
208
+ /** @Id @ ManyToOne(targetEntity=" Article" , inversedBy=" attributes") */
209
+ private Article|null $article;
210
210
211
- #[Id, Column(type: ' string')]
211
+ /** @Id @ Column(type=" string") */
212
212
private string $attribute;
213
213
214
- #[ Column(type: ' string')]
214
+ /** @ Column(type=" string") */
215
215
private string $value;
216
216
217
- public function __construct(string $name, string $value, Article $article)
217
+ public function __construct($name, $value, $article)
218
218
{
219
219
$this->attribute = $name;
220
220
$this->value = $value;
@@ -256,7 +256,7 @@ One good example for this is a user-address relationship:
256
256
#[Entity]
257
257
class User
258
258
{
259
- #[Id, Column(type: 'integer') , GeneratedValue]
259
+ #[Id, Column, GeneratedValue]
260
260
private int|null $id = null;
261
261
}
262
262
@@ -284,18 +284,18 @@ of products purchased and maybe even the current price.
284
284
#[Entity]
285
285
class Order
286
286
{
287
- #[Id, Column(type: 'integer') , GeneratedValue]
287
+ #[Id, Column, GeneratedValue]
288
288
private int|null $id = null;
289
289
290
290
/** @var ArrayCollection<int , OrderItem > */
291
291
#[OneToMany(targetEntity: OrderItem::class, mappedBy: 'order')]
292
292
private Collection $items;
293
293
294
- #[Column(type: 'boolean') ]
294
+ #[Column]
295
295
private bool $paid = false;
296
- #[Column(type: 'boolean') ]
296
+ #[Column]
297
297
private bool $shipped = false;
298
- #[Column(type: 'datetime') ]
298
+ #[Column]
299
299
private DateTime $created;
300
300
301
301
public function __construct(
@@ -310,16 +310,16 @@ of products purchased and maybe even the current price.
310
310
#[Entity]
311
311
class Product
312
312
{
313
- #[Id, Column(type: 'integer') , GeneratedValue]
313
+ #[Id, Column, GeneratedValue]
314
314
private int|null $id = null;
315
315
316
- #[Column(type: 'string') ]
316
+ #[Column]
317
317
private string $name;
318
318
319
- #[Column(type: 'decimal') ]
320
- private float $currentPrice;
319
+ #[Column]
320
+ private int $currentPrice;
321
321
322
- public function getCurrentPrice(): float
322
+ public function getCurrentPrice(): int
323
323
{
324
324
return $this->currentPrice;
325
325
}
@@ -334,11 +334,11 @@ of products purchased and maybe even the current price.
334
334
#[Id, ManyToOne(targetEntity: Product::class)]
335
335
private Product|null $product = null;
336
336
337
- #[Column(type: 'integer') ]
337
+ #[Column]
338
338
private int $amount = 1;
339
339
340
- #[Column(type: 'decimal') ]
341
- private float $offeredPrice;
340
+ #[Column]
341
+ private int $offeredPrice;
342
342
343
343
public function __construct(Order $order, Product $product, int $amount = 1)
344
344
{
0 commit comments