File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,13 @@ Behavior Changes
1515New Features
1616============
1717
18+ ORM
19+ ---
20+
21+ - ``CounterCacheBehavior::updateCounterCache() `` has been addded. This method
22+ allows you to update the counter cache values for all records of the configured
23+ associations.
24+
1825Error
1926-----
2027
Original file line number Diff line number Diff line change @@ -162,3 +162,28 @@ with the same code as described above.::
162162 ]);
163163
164164Finally clear all caches with ``bin/cake cache clear_all `` and try it out.
165+
166+ Manually updating counter caches
167+ ================================
168+
169+ .. php :method :: updateCounterCache(?string $assocName = null, int $limit = 100, ?int $page = null): void
170+
171+ The ``updateCounterCache() `` method allows you to update the counter cache values
172+ for one or all configured associations in batches. This can be useful, for example,
173+ to update the counter cache after importing data directly into the database.::
174+
175+ // Update the counter cache for all configured associations
176+ $table->updateCounterCache();
177+
178+ // Update the counter cache for a specific association, 200 records per batch
179+ $table->updateCounterCache('Articles', 200);
180+
181+ // Update only the first page of records
182+ $table->updateCounterCache('Articles', page: 1);
183+
184+ .. versionadded :: 5.2.0
185+
186+ .. note ::
187+
188+ This methods won't update the counter cache values for fields which are
189+ configured to use a closure to get the count value.
You can’t perform that action at this time.
0 commit comments