From 5033dbb8ea90d7d79de4f6a50cb34cf6d790b63f Mon Sep 17 00:00:00 2001 From: celsowm Date: Mon, 26 Jun 2023 21:15:28 -0300 Subject: [PATCH 1/2] Update query-builder.rst two examples of setConjunction() --- en/orm/query-builder.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/en/orm/query-builder.rst b/en/orm/query-builder.rst index 79bf4a1cc9..afb28aa9e2 100644 --- a/en/orm/query-builder.rst +++ b/en/orm/query-builder.rst @@ -1177,6 +1177,35 @@ expression objects to add snippets of SQL to your queries:: Using expression objects leaves you vulnerable to SQL injection. You should never use untrusted data into expressions. +Expression Conjuction +----------------------- + +It is possible to Changes for changing the conjunction used to join conditions in +a query expression using the method ``setConjunction``:: + + $query = $articles->find(); + $expr = $query->newExpr(['1','1'])->setConjunction('+'); + $query->select(['two' => $expr]); + +And can be used combined with aggregations too:: + + $query = $products->find(); + $query->select(function ($query) { + $stockQuantity = $query->func()->sum('Stocks.quantity'); + $totalStockValue = $query->func()->sum( + $query->newExpr(['Stocks.quantity', 'Products.unit_price']) + ->setConjunction('*') + ); + return [ + 'Products.name', + 'stock_quantity' => $stockQuantity, + 'Products.unit_price', + 'total_stock_value' => $totalStockValue + ]; + }) + ->innerJoinWith('Stocks') + ->groupBy(['Products.id', 'Products.name', 'Products.unit_price']); + Getting Results =============== From 6c2d92f328186df96e475f8c52c405c6cc055314 Mon Sep 17 00:00:00 2001 From: celsowm Date: Mon, 26 Jun 2023 21:25:22 -0300 Subject: [PATCH 2/2] Update query-builder.rst fix text --- en/orm/query-builder.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/en/orm/query-builder.rst b/en/orm/query-builder.rst index afb28aa9e2..28e3685229 100644 --- a/en/orm/query-builder.rst +++ b/en/orm/query-builder.rst @@ -1180,8 +1180,8 @@ expression objects to add snippets of SQL to your queries:: Expression Conjuction ----------------------- -It is possible to Changes for changing the conjunction used to join conditions in -a query expression using the method ``setConjunction``:: +It is possible to change the conjunction used to join conditions in a query +expression using the method ``setConjunction``:: $query = $articles->find(); $expr = $query->newExpr(['1','1'])->setConjunction('+');