#89474Categories: Database not updated if a item is assigned
Description
Hi,
I have noticed that the database is not updated if I assign items (pages or news item) to a category. Also if a item is deleted, the database (sys_category) isn’t updated.
I have tested this with news (tx_news) and pages.
- Let’s say we have created a news entry or page and assigned it to “category 1”. After saving, the field “items” of the table “sys_category” should be set to “1” – but it isn’t.
- If I go to the category in the backend, the item is assigned correctly to “category 1” as expected. I save the category with the assigned category and now the database is updated and the field “item” for “category 1” is set to “1”.
- If I delete the news item or page in the backend I’d expect the field “item” for “category 1” to be set to “0”. But it isn’t, it is still on “1”. So I have to go to the category in the backend again. Open and save it. Then the database is updated correctly
- TYPO3 9.5.10
- PHP 7.2.10
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Related issues 1
History 3
-
Christian Kuhn changed Related to #89097 <span data-processor="relativetime" data-value="2020-10-20T13:02:19+00:00" > 10/20/20, 13:02 </span>
-
Benni Mack commented and changed status
NewClosed <span data-processor="relativetime" data-value="2026-10-13T12:53:44+00:00" > 10/13/26, 12:53 </span>
Verified on main (15.0.0-dev) with a functional test: assigning a category to a page (existing or new) leaves sys_category.items at 0, and deleting the page leaves it at 1. The value is only recalculated when the category record itself is saved.
This is how bidirectional MM fields work: DataHandler stores the relation count only in the field of the record being saved (here pages.categories). The opposite side’s column is not updated.
The number in sys_category.items is meaningless as long as the Core API is used: the backend form, the category tree, the reference index and RelationHandler all resolve relations through sys_category_record_mm and never read this value. Keeping it in sync would mean an extra write on every save of every categorised record for a value nothing reads.
If you need the number of records in a category, count the rows in sys_category_record_mm (plus the record’s deleted/hidden state, since soft-deleted records keep their MM rows) rather than relying on sys_category.items.
Since the stored value is unused, dropping the database column for sys_category.items in a future major version is an option worth considering; the relations themselves stay in sys_category_record_mm.
Closing this, together with the related #89097.