From bc48fbcaf3621a2fa4e44492e604866a6b5831e4 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Tue, 24 Apr 2018 21:02:34 +0200 Subject: [PATCH 1/2] Doctrine: Use only integer prices --- doctrine.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doctrine.rst b/doctrine.rst index 39c9e6c22de..ecd2b1e9751 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -335,7 +335,7 @@ and save it! $product = new Product(); $product->setName('Keyboard'); - $product->setPrice(19.99); + $product->setPrice(1999); $product->setDescription('Ergonomic and stylish!'); // tell Doctrine you want to (eventually) save the Product (no queries yet) @@ -441,7 +441,7 @@ Once you have a repository object, you have many helper methods:: // or find by name and price $product = $repository->findOneBy([ 'name' => 'Keyboard', - 'price' => 19.99, + 'price' => 1999, ]); // look for multiple Product objects matching the name, ordered by price @@ -624,7 +624,7 @@ This uses Doctrine's `Query Builder`_: a very powerful and user-friendly way to write custom queries. Now, you can call this method on the repository:: // from inside a controller - $minPrice = 10; + $minPrice = 1000; $products = $this->getDoctrine() ->getRepository(Product::class) @@ -654,7 +654,7 @@ In addition to the query builder, you can also query with `Doctrine Query Langua FROM App\Entity\Product p WHERE p.price > :price ORDER BY p.price ASC' - )->setParameter('price', 10); + )->setParameter('price', 1000); // returns an array of Product objects return $query->execute(); @@ -675,7 +675,7 @@ Or directly with SQL if you need to:: ORDER BY p.price ASC '; $stmt = $conn->prepare($sql); - $stmt->execute(['price' => 10]); + $stmt->execute(['price' => 1000]); // returns an array of arrays (i.e. a raw data set) return $stmt->fetchAll(); From a580cc9741d69894cc6ab846439c450e1e1db7f5 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Tue, 24 Apr 2018 21:03:43 +0200 Subject: [PATCH 2/2] Flex recipe: Store price as int instead of string --- quick_tour/flex_recipes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quick_tour/flex_recipes.rst b/quick_tour/flex_recipes.rst index e6a6a4e3eaa..a1d0de28dc4 100644 --- a/quick_tour/flex_recipes.rst +++ b/quick_tour/flex_recipes.rst @@ -213,7 +213,7 @@ rich API for a ``product`` table? Create a ``Product`` entity and give it the private $name; /** - * @ORM\Column(type="string") + * @ORM\Column(type="int") */ private $price;