Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit59c6b0d

Browse files
committed
tweaks thanks to@yceruto
1 parent2b0236f commit59c6b0d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

‎doctrine.rst‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ in the database. This is usually done with annotations:
130130
private $id;
131131
132132
/**
133-
* @ORM\Column(type="string", length=100, nullable=false)
133+
* @ORM\Column(type="string", length=100)
134134
*/
135135
private $name;
136136
137137
/**
138-
* @ORM\Column(type="decimal", scale=2, nullable=false)
138+
* @ORM\Column(type="decimal", scale=2, nullable=true)
139139
*/
140140
private $price;
141141
}
@@ -153,11 +153,10 @@ in the database. This is usually done with annotations:
153153
name:
154154
type:string
155155
length:100
156-
nullable:false
157156
price:
158157
type:decimal
159158
scale:2
160-
nullable:false
159+
nullable:true
161160
162161
..code-block::xml
163162
@@ -172,8 +171,8 @@ in the database. This is usually done with annotations:
172171
<idname="id"type="integer">
173172
<generatorstrategy="AUTO" />
174173
</id>
175-
<fieldname="name"type="string"length="100"nullable="false"/>
176-
<fieldname="price"type="decimal"scale="2"nullable="false" />
174+
<fieldname="name"type="string"length="100" />
175+
<fieldname="price"type="decimal"scale="2"nullable="true" />
177176
</entity>
178177
</doctrine-mapping>
179178
@@ -455,8 +454,8 @@ Once you have a repository object, you have many helper methods::
455454

456455
// query for multiple Product objects matching the name, ordered by price
457456
$products = $repository->findBy(
458-
array('name' => 'Keyboard'),
459-
array('price' => 'ASC')
457+
['name' => 'Keyboard'],
458+
['price' => 'ASC']
460459
);
461460

462461
// find *all* Product objects
@@ -584,6 +583,10 @@ But what if you need a more complex query? When you generated your entity with
584583

585584
class ProductRepository extends ServiceEntityRepository
586585
{
586+
public function __construct(RegistryInterface $registry)
587+
{
588+
parent::__construct($registry, Product::class);
589+
}
587590
}
588591

589592
When you fetch your repository (i.e. ``->getRepository(Product::class)``, it is
@@ -598,6 +601,8 @@ a new method for this to your repository::
598601
// ...
599602
class ProductRepository extends ServiceEntityRepository
600603
{
604+
// ...
605+
601606
/**
602607
* @param $price
603608
* @return Product[]
@@ -672,7 +677,7 @@ Or directly with SQL if you need to::
672677
ORDER BY p.price ASC
673678
';
674679
$stmt = $conn->prepare($sql);
675-
$stmt->execute(array('price' => 10));
680+
$stmt->execute(['price' => 10]);
676681

677682
// returns an array of arrays (i.e. a raw data set)
678683
return $stmt->fetchAll();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp