Skip to content

Commit

Permalink
Merge pull request cakephp#7637 from celsowm/patch-13
Browse files Browse the repository at this point in the history
Update query-builder.rst
  • Loading branch information
markstory authored Jun 27, 2023
2 parents 2c19867 + 6c2d92f commit 316cfe5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions en/orm/query-builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 change 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
===============

Expand Down

0 comments on commit 316cfe5

Please sign in to comment.