@@ -130,12 +130,12 @@ in the database. This is usually done with annotations:
130
130
private $id;
131
131
132
132
/**
133
- * @ORM\Column(type="string", length=100, nullable=false )
133
+ * @ORM\Column(type="string", length=100)
134
134
*/
135
135
private $name;
136
136
137
137
/**
138
- * @ORM\Column(type="decimal", scale=2, nullable=false )
138
+ * @ORM\Column(type="decimal", scale=2, nullable=true )
139
139
*/
140
140
private $price;
141
141
}
@@ -153,11 +153,10 @@ in the database. This is usually done with annotations:
153
153
name :
154
154
type : string
155
155
length : 100
156
- nullable : false
157
156
price :
158
157
type : decimal
159
158
scale : 2
160
- nullable : false
159
+ nullable : true
161
160
162
161
.. code-block :: xml
163
162
@@ -172,8 +171,8 @@ in the database. This is usually done with annotations:
172
171
<id name =" id" type =" integer" >
173
172
<generator strategy =" AUTO" />
174
173
</id >
175
- <field name =" name" type =" string" length =" 100" nullable = " false " />
176
- <field name =" price" type =" decimal" scale =" 2" nullable =" false " />
174
+ <field name =" name" type =" string" length =" 100" />
175
+ <field name =" price" type =" decimal" scale =" 2" nullable =" true " />
177
176
</entity >
178
177
</doctrine-mapping >
179
178
@@ -455,8 +454,8 @@ Once you have a repository object, you have many helper methods::
455
454
456
455
// query for multiple Product objects matching the name, ordered by price
457
456
$products = $repository->findBy(
458
- array( 'name' => 'Keyboard') ,
459
- array( 'price' => 'ASC')
457
+ [ 'name' => 'Keyboard'] ,
458
+ [ 'price' => 'ASC']
460
459
);
461
460
462
461
// find *all* Product objects
@@ -584,6 +583,10 @@ But what if you need a more complex query? When you generated your entity with
584
583
585
584
class ProductRepository extends ServiceEntityRepository
586
585
{
586
+ public function __construct(RegistryInterface $registry)
587
+ {
588
+ parent::__construct($registry, Product::class);
589
+ }
587
590
}
588
591
589
592
When you fetch your repository (i.e. ``->getRepository(Product::class) ``, it is
@@ -598,6 +601,8 @@ a new method for this to your repository::
598
601
// ...
599
602
class ProductRepository extends ServiceEntityRepository
600
603
{
604
+ // ...
605
+
601
606
/**
602
607
* @param $price
603
608
* @return Product[]
@@ -672,7 +677,7 @@ Or directly with SQL if you need to::
672
677
ORDER BY p.price ASC
673
678
';
674
679
$stmt = $conn->prepare($sql);
675
- $stmt->execute(array( 'price' => 10) );
680
+ $stmt->execute([ 'price' => 10] );
676
681
677
682
// returns an array of arrays (i.e. a raw data set)
678
683
return $stmt->fetchAll();
0 commit comments