Skip to content

Commit ed7860d

Browse files
committed
Update use of behavior methods as mixins
Refs cakephp/cakephp#18322
1 parent a3e9aec commit ed7860d

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

en/orm/behaviors/counter-cache.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ for all records of one or all configured associations in batches. This can be us
173173
for example, to update the counter cache after importing data directly into the database.::
174174

175175
// Update the counter cache for all configured associations
176-
$table->updateCounterCache();
176+
$table->getBehavior('CounterCache')->updateCounterCache();
177177

178178
// Update the counter cache for a specific association, 200 records per batch
179-
$table->updateCounterCache('Articles', 200);
179+
$table->getBehavior('CounterCache')->updateCounterCache('Articles', 200);
180180

181181
// Update only the first page of records
182-
$table->updateCounterCache('Articles', page: 1);
182+
$table->getBehavior('CounterCache')->updateCounterCache('Articles', page: 1);
183183

184184
.. versionadded:: 5.2.0
185185

en/orm/behaviors/timestamp.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ changing any other properties. This is sometimes referred to as 'touching'
6565
a record. In CakePHP you can use the ``touch()`` method to do exactly this::
6666

6767
// Touch based on the Model.beforeSave event.
68-
$articles->touch($article);
68+
$articles->getBehavior('Timestamp')->touch($article);
6969

7070
// Touch based on a specific event.
71-
$orders->touch($order, 'Orders.completed');
71+
$orders->getBehavior('Timestamp')->touch($order, 'Orders.completed');
7272

7373
After you have saved the entity, the field is updated.
7474

en/orm/behaviors/translate.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ modifying the application's state. For these scenarios use the behavior's
350350
I18n::setLocale('en'); // reset for illustration
351351

352352
// specific locale.
353-
$this->Articles->setLocale('es');
353+
$this->Articles->getBehavior('Translate')->setLocale('es');
354354

355355
$article = $this->Articles->get(12);
356356
echo $article->title; // Echoes 'Un Artículo', yay piece of cake!
@@ -361,8 +361,8 @@ to call the method on each table, for example::
361361

362362
I18n::setLocale('en'); // reset for illustration
363363

364-
$this->Articles->setLocale('es');
365-
$this->Articles->Categories->setLocale('es');
364+
$this->Articles->getBehavior('Translate')->setLocale('es');
365+
$this->Articles->Categories->getBehavior('Translate')->setLocale('es');
366366

367367
$data = $this->Articles->find('all', contain: ['Categories']);
368368

@@ -375,9 +375,9 @@ Querying Translated Fields
375375
TranslateBehavior does not substitute find conditions by default. You need to use
376376
``translationField()`` method to compose find conditions on translated fields::
377377

378-
$this->Articles->setLocale('es');
378+
$this->Articles->getBehavior('Translate')->setLocale('es');
379379
$query = $this->Articles->find()->where([
380-
$this->Articles->translationField('title') => 'Otro Título'
380+
$this->Articles->getBehavior('Translate')->translationField('title') => 'Otro Título'
381381
]);
382382

383383
Saving in Another Language
@@ -442,7 +442,7 @@ default language directly to the table::
442442

443443
$article->title = 'Mi Primer Artículo';
444444

445-
$this->Articles->setLocale('es');
445+
$this->Articles->getBehavior('Translate')->setLocale('es');
446446
$this->Articles->save($article);
447447

448448
Setting the language directly in the table is useful when you need to both

en/orm/behaviors/tree.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ You can verify it works by getting any row from the table and asking for the
6161
count of descendants it has::
6262

6363
$node = $categories->get(1);
64-
echo $categories->childCount($node);
64+
echo $categories->getBehavior('Tree')->childCount($node);
6565

6666
Getting direct descendents
6767
--------------------------
@@ -179,13 +179,13 @@ having to change their parent::
179179
$node = $categories->get(5);
180180

181181
// Move the node so it shows up one position up when listing children.
182-
$categories->moveUp($node);
182+
$categories->getBehavior('Tree')->moveUp($node);
183183

184184
// Move the node to the top of the list inside the same level.
185-
$categories->moveUp($node, true);
185+
$categories->getBehavior('Tree')->moveUp($node, true);
186186

187187
// Move the node to the bottom.
188-
$categories->moveDown($node, true);
188+
$categories->getBehavior('Tree')->moveDown($node, true);
189189

190190
Configuration
191191
=============
@@ -237,12 +237,12 @@ In the previous example, all tree operations will be scoped to only the rows
237237
having the column ``country_name`` set to 'Brazil'. You can change the scoping
238238
on the fly by using the 'config' function::
239239

240-
$this->behaviors()->Tree->setConfig('scope', ['country_name' => 'France']);
240+
$this->getBehavior('Tree')->setConfig('scope', ['country_name' => 'France']);
241241

242242
Optionally, you can have a finer grain control of the scope by passing a closure
243243
as the scope::
244244

245-
$this->behaviors()->Tree->setConfig('scope', function ($query) {
245+
$this->getBehavior('Tree')->setConfig('scope', function ($query) {
246246
$country = $this->getConfigureContry(); // A made-up function
247247
return $query->where(['country_name' => $country]);
248248
});
@@ -311,7 +311,7 @@ is also possible to only delete one node and re-assign all children to the
311311
immediately superior parent node in the tree::
312312

313313
$aCategory = $categoriesTable->get(10);
314-
$categoriesTable->removeFromTree($aCategory);
314+
$categoriesTable->getBehavior('Tree')->removeFromTree($aCategory);
315315
$categoriesTable->delete($aCategory);
316316

317317
All children nodes will be kept and a new parent will be assigned to them.

0 commit comments

Comments
 (0)