Skip to content

Commit ef6598c

Browse files
committed
Update 5.3 migration guide
Refs cakephp/cakephp#18916
1 parent b08586f commit ef6598c

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

en/appendices/5-3-migration-guide.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ View
3737
Deprecations
3838
============
3939

40+
Database
41+
--------
42+
- ``Query::newExpr()`` is deprecated. Use ``Query::expr()`` instead.
43+
4044
Form
4145
----
4246

en/orm/query-builder.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,11 @@ If we wished to know how many published articles are in our database, we could u
511511
To do this with the query builder, we'd use the following code::
512512

513513
$query = $articles->find();
514-
$publishedCase = $query->newExpr()
514+
$publishedCase = $query->expr()
515515
->case()
516516
->when(['published' => 'Y'])
517517
->then(1);
518-
$unpublishedCase = $query->newExpr()
518+
$unpublishedCase = $query->expr()
519519
->case()
520520
->when(['published' => 'N'])
521521
->then(1);
@@ -531,10 +531,10 @@ cities into SMALL, MEDIUM, or LARGE based on population size, we could do the
531531
following::
532532

533533
$query = $cities->find();
534-
$sizing = $query->newExpr()->case()
534+
$sizing = $query->expr()->case()
535535
->when(['population <' => 100000])
536536
->then('SMALL')
537-
->when($query->newExpr()->between('population', 100000, 999000))
537+
->when($query->expr()->between('population', 100000, 999000))
538538
->then('MEDIUM')
539539
->when(['population >=' => 999001])
540540
->then('LARGE');
@@ -557,9 +557,9 @@ as it can create SQL injection vulnerabilities::
557557
For more complex scenarios you can use ``QueryExpression`` objects and bound
558558
values::
559559

560-
$userValue = $query->newExpr()
560+
$userValue = $query->expr()
561561
->case()
562-
->when($query->newExpr('population >= :userData'))
562+
->when($query->expr('population >= :userData'))
563563
->then(123, 'integer');
564564

565565
$query->select(['val' => $userValue])
@@ -575,7 +575,7 @@ a different type you can declare the desired type::
575575

576576
You can create ``if ... then ... else`` conditions by using ``else()``::
577577

578-
$published = $query->newExpr()
578+
$published = $query->expr()
579579
->case()
580580
->when(['published' => true])
581581
->then('Y');
@@ -585,7 +585,7 @@ You can create ``if ... then ... else`` conditions by using ``else()``::
585585

586586
Also, it's possible to create the simple variant by passing a value to ``case()``::
587587

588-
$published = $query->newExpr()
588+
$published = $query->expr()
589589
->case($query->identifier('published'))
590590
->when(true)
591591
->then('Y');
@@ -603,9 +603,9 @@ size, we could do the following::
603603
->where(function (QueryExpression $exp, SelectQuery $q) {
604604
return $exp->addCase(
605605
[
606-
$q->newExpr()->lt('population', 100000),
607-
$q->newExpr()->between('population', 100000, 999000),
608-
$q->newExpr()->gte('population', 999001),
606+
$q->expr()->lt('population', 100000),
607+
$q->expr()->between('population', 100000, 999000),
608+
$q->expr()->gte('population', 999001),
609609
],
610610
['SMALL', 'MEDIUM', 'LARGE'], # values matching conditions
611611
['string', 'string', 'string'] # type of each value
@@ -624,7 +624,7 @@ automatically produce an ``if .. then .. else`` statement::
624624
->where(function (QueryExpression $exp, SelectQuery $q) {
625625
return $exp->addCase(
626626
[
627-
$q->newExpr()->eq('population', 0),
627+
$q->expr()->eq('population', 0),
628628
],
629629
['DESERTED', 'INHABITED'], # values matching conditions
630630
['string', 'string'] # type of each value
@@ -758,12 +758,12 @@ For example::
758758

759759
$query = $articles->find()->where(function (QueryExpression $exp, SelectQuery $query) {
760760
// Use add() to add multiple conditions for the same field.
761-
$author = $query->newExpr()->or(['author_id' => 3])->add(['author_id' => 2]);
762-
$published = $query->newExpr()->and(['published' => true, 'view_count' => 10]);
761+
$author = $query->expr()->or(['author_id' => 3])->add(['author_id' => 2]);
762+
$published = $query->expr()->and(['published' => true, 'view_count' => 10]);
763763

764764
return $exp->or([
765765
'promoted' => true,
766-
$query->newExpr()->and([$author, $published])
766+
$query->expr()->and([$author, $published])
767767
]);
768768
});
769769

@@ -1176,7 +1176,7 @@ When you cannot construct the SQL you need using the query builder, you can use
11761176
expression objects to add snippets of SQL to your queries::
11771177

11781178
$query = $articles->find();
1179-
$expr = $query->newExpr()->add('1 + 1');
1179+
$expr = $query->expr()->add('1 + 1');
11801180
$query->select(['two' => $expr]);
11811181

11821182
``Expression`` objects can be used with any query builder methods like
@@ -1210,7 +1210,7 @@ It is possible to change the conjunction used to join conditions in a query
12101210
expression using the method ``setConjunction``::
12111211

12121212
$query = $articles->find();
1213-
$expr = $query->newExpr(['1','1'])->setConjunction('+');
1213+
$expr = $query->expr(['1','1'])->setConjunction('+');
12141214
$query->select(['two' => $expr]);
12151215

12161216
And can be used combined with aggregations too::
@@ -1219,7 +1219,7 @@ And can be used combined with aggregations too::
12191219
$query->select(function ($query) {
12201220
$stockQuantity = $query->func()->sum('Stocks.quantity');
12211221
$totalStockValue = $query->func()->sum(
1222-
$query->newExpr(['Stocks.quantity', 'Products.unit_price'])
1222+
$query->expr(['Stocks.quantity', 'Products.unit_price'])
12231223
->setConjunction('*')
12241224
);
12251225

@@ -1664,7 +1664,7 @@ data::
16641664

16651665
Raw expressions are never safe::
16661666

1667-
$expr = $query->newExpr()->add($userData);
1667+
$expr = $query->expr()->add($userData);
16681668
$query->select(['two' => $expr]);
16691669

16701670
Binding values

0 commit comments

Comments
 (0)