Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/en/appendices/6-0-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,40 @@ Some properties have also been renamed to better reflect their purpose. These ar

### Database

- Operators in condition-array keys, such as `['views >' => 1000]` or
`['id IN' => $ids]`, are no longer supported and raise an
Comment on lines +141 to +142

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be a very rough upgrade. I don't think this is a good idea.

`InvalidArgumentException`. Use the predicate functions in
`Cake\Database\Expression` instead. Plain equality conditions, nested boolean
arrays, and the fluent `QueryExpression` API remain supported.

```php
use function Cake\Database\Expression\{equals, greaterThan, in, notEquals};

// Before (CakePHP 5.x)
$query->where([
'views >' => 1000,
'id IN' => $ids,
'parent_id IS' => $parentId,
'deleted IS NOT' => null,
]);

// After (CakePHP 6.x)
$query->where([
'views' => greaterThan(1000),
'id' => in($ids),
'parent_id' => equals($parentId),
'deleted' => notEquals(null),
]);
```

`equals()` and `notEquals()` generate `IS NULL` and `IS NOT NULL` when their
value is `null`. Use `isNull()` and `isNotNull()` for explicit null checks.
Predicates infer binding types from the query; pass `type:` to override them.
The [upgrade tool](6-0-upgrade-guide#upgrade-tool-use) includes this conversion
in its `cakephp60` rules. See
[Predicate Functions](../orm/query-builder#predicate-functions) for the full
function reference and examples.

- Binary columns now use `binary` for fixed-length data and `varbinary` for
variable-length data. In migration `addColumn()` calls, remove
`'fixed' => true` from fixed-length `binary` columns, and change variable-length
Expand Down Expand Up @@ -262,6 +296,13 @@ still uses other Diactoros classes or functions, declare

## New Features

### Database

- Namespaced predicate functions build field-keyed conditions with bound values.
They support comparisons, ranges, membership, null checks, and custom SQL
operators. The returned immutable predicates can be reused across queries.
See [Predicate Functions](../orm/query-builder#predicate-functions).

### Http

- The HTTP client supports live response bodies through the Stream adapter with
Expand Down
4 changes: 3 additions & 1 deletion docs/en/development/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,16 @@ the source using the `RequestToDtoSource` enum:
use Cake\Controller\Attribute\RequestToDto;
use Cake\Controller\Attribute\Enum\RequestToDtoSource;

use function Cake\Database\Expression\like;

class ArticlesController extends AppController
{
// Use query string parameters
public function search(
#[RequestToDto(source: RequestToDtoSource::Query)] SearchCriteriaDto $criteria
): void {
$articles = $this->Articles->find()
->where(['title LIKE' => "%{$criteria->query}%"])
->where(['title' => like("%{$criteria->query}%")])
->limit($criteria->limit);
}

Expand Down
4 changes: 3 additions & 1 deletion docs/en/orm/behaviors/tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ foreach ($descendants as $category) {
If you need to pass conditions you do so as per normal:

```php
use function Cake\Database\Expression\like;

$descendants = $categories
->find('children', for: 1)
->where(['name LIKE' => '%Foo%'])
->where(['name' => like('%Foo%')])
->all();

foreach ($descendants as $category) {
Expand Down
4 changes: 3 additions & 1 deletion docs/en/orm/database-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ $results = $connection
Instead of writing the SQL manually, you can use the query builder:

```php
use function Cake\Database\Expression\greaterThan;

// Prior to 4.5 use $connection->query() instead.
$results = $connection
->selectQuery('*', 'articles')
->where(['created >' => new DateTime('1 day ago')], ['created' => 'datetime'])
->where(['created' => greaterThan(new DateTime('1 day ago'))], ['created' => 'datetime'])
->orderBy(['title' => 'DESC'])
->execute()
->fetchAll('assoc');
Expand Down
Loading
Loading