Skip to content

Commit bef08fe

Browse files
Docs: Removing type: 'integer' from mappings
Yet another micro-PR ;-) - as requested at doctrine#10364 (comment) I also changed `$currentPrice` from `float` to `int`, since IMO it's better to store prices as `int` (=cents). Question: Is there a reason why most typehints are `int|null`, instead of `?int`? Should I change them?
1 parent 0852847 commit bef08fe

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

docs/en/tutorials/composite-primary-keys.rst

+20-20
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ and year of production as primary keys:
3232
class Car
3333
{
3434
public function __construct(
35-
#[Id, Column(type: 'string')]
35+
#[Id, Column]
3636
private string $name,
37-
#[Id, Column(type: 'integer')]
37+
#[Id, Column]
3838
private int $year,
3939
) {
4040
}
@@ -131,7 +131,7 @@ And for querying you can use arrays to both DQL and EntityRepositories:
131131
132132
$dql = "SELECT c FROM VehicleCatalogue\Model\Car c WHERE c.id = ?1";
133133
$audi = $em->createQuery($dql)
134-
->setParameter(1, array("name" => "Audi A8", "year" => 2010))
134+
->setParameter(1, ["name" => "Audi A8", "year" => 2010])
135135
->getSingleResult();
136136
137137
You can also use this entity in associations. Doctrine will then generate two foreign keys one for ``name``
@@ -179,9 +179,9 @@ We keep up the example of an Article with arbitrary attributes, the mapping look
179179
#[Entity]
180180
class Article
181181
{
182-
#[Id, Column(type: 'integer'), GeneratedValue]
182+
#[Id, Column, GeneratedValue]
183183
private int|null $id = null;
184-
#[Column(type: 'string')]
184+
#[Column]
185185
private string $title;
186186
187187
/** @var ArrayCollection<string, ArticleAttribute> */
@@ -200,10 +200,10 @@ We keep up the example of an Article with arbitrary attributes, the mapping look
200200
#[Id, ManyToOne(targetEntity: Article::class, inversedBy: 'attributes')]
201201
private Article $article;
202202
203-
#[Id, Column(type: 'string')]
203+
#[Id, Column]
204204
private string $attribute;
205205
206-
#[Column(type: 'string')]
206+
#[Column]
207207
private string $value;
208208
209209
public function __construct(string $name, string $value, Article $article)
@@ -317,7 +317,7 @@ One good example for this is a user-address relationship:
317317
#[Entity]
318318
class User
319319
{
320-
#[Id, Column(type: 'integer'), GeneratedValue]
320+
#[Id, Column, GeneratedValue]
321321
private int|null $id = null;
322322
}
323323
@@ -365,18 +365,18 @@ of products purchased and maybe even the current price.
365365
#[Entity]
366366
class Order
367367
{
368-
#[Id, Column(type: 'integer'), GeneratedValue]
368+
#[Id, Column, GeneratedValue]
369369
private int|null $id = null;
370370
371371
/** @var ArrayCollection<int, OrderItem> */
372372
#[OneToMany(targetEntity: OrderItem::class, mappedBy: 'order')]
373373
private Collection $items;
374374
375-
#[Column(type: 'boolean')]
375+
#[Column]
376376
private bool $paid = false;
377-
#[Column(type: 'boolean')]
377+
#[Column]
378378
private bool $shipped = false;
379-
#[Column(type: 'datetime')]
379+
#[Column]
380380
private DateTime $created;
381381
382382
public function __construct(
@@ -391,16 +391,16 @@ of products purchased and maybe even the current price.
391391
#[Entity]
392392
class Product
393393
{
394-
#[Id, Column(type: 'integer'), GeneratedValue]
394+
#[Id, Column, GeneratedValue]
395395
private int|null $id = null;
396396
397-
#[Column(type: 'string')]
397+
#[Column]
398398
private string $name;
399399
400-
#[Column(type: 'decimal')]
401-
private float $currentPrice;
400+
#[Column]
401+
private int $currentPrice;
402402
403-
public function getCurrentPrice(): float
403+
public function getCurrentPrice(): int
404404
{
405405
return $this->currentPrice;
406406
}
@@ -415,11 +415,11 @@ of products purchased and maybe even the current price.
415415
#[Id, ManyToOne(targetEntity: Product::class)]
416416
private Product|null $product = null;
417417
418-
#[Column(type: 'integer')]
418+
#[Column]
419419
private int $amount = 1;
420420
421-
#[Column(type: 'decimal')]
422-
private float $offeredPrice;
421+
#[Column]
422+
private int $offeredPrice;
423423
424424
public function __construct(Order $order, Product $product, int $amount = 1)
425425
{

0 commit comments

Comments
 (0)