Issue Bug Closed

#89097Sys_category - field "items" on database gets updated only when reordering the "items"

Riccardo De Contardi 09/05/19, 22:22 updated 10/13/26, 12:53

Description

This issue is filled with my findings in investigating the issue #73644

When you add a category to some items

  • if you edit the category and look at the tab “items” you will find all the items with that category
  • if you look at the database, table sys_category > column “items” you would expect to see here the same number of items, but it does not always happen; this is why I tried to discover what happens with some tests.

Preliminary stuff:

create new category ZZZZ

Test 1

1) Create or open an existing page and assign category ZZZZ
1.1) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “0”

Test 2

2) Create or open an existing content element and assign category ZZZZ
2.1) Create or open an existing content element and assign category ZZZZ
2.2) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “0”

Test 3

3) Edit category ZZZZ > tab Items > remove the “page” item
3.1) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “2”

Test 4

4) Open an existing file in file module and assign category ZZZZ
4.1) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “2”

Test 5

5) Edit category ZZZZ > tab Items > remove the “CE” items
5.1) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “1”

Test 6

6) Create or open an existing page and assign category ZZZZ
6.1) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “1”

From here, things are getting weird:

Test 7

7) Edit category ZZZZ > tab Items > remove the “sys_file_metadata” item
7.1) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “1” (!) I would have expected “0” as the test 1.1!!
Adding another page, or adding a CE, it still reads “1”

Test 8

8) Remove every item from the category
8.1) Create or open an existing content element and assign category ZZZZ
8.2) Create or open an existing content element and assign category ZZZZ
8.3) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “0” (!) I would have expected “2” as the test 3.1!!

Test 9

9) Create or open an existing page and assign category ZZZZ
9.1) Edit category ZZZZ > tab Items > remove the “CE” items
9.2) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “1” (!)

Test 10

10) Open an existing file in file module and assign category ZZZZ
10.1) Open an existing file in file module and assign category ZZZZ
10.2) Create or open an existing content element and assign category ZZZZ
10.3) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “0” (!)

Test 11

11) Create or open an existing page and assign category ZZZZ
11.1) Edit category ZZZZ > tab Items > remove the “CE” item
11.2) Open the database > Table sys_category > look for the ZZZZ record > the items column reads “3” (!) (exact number of the items including page!)

What I have learned so far

The behavior seems really weird and inconsistent, but from my tests it seems that

  • when you enter one or more elements of the same type, the items column in the DB is not updated and reads “0”
  • adding an element of a different type will not update it
  • when you delete one element, it seems that the order of the elements is altered and this somehow triggers the update of the field
  • this behavior seems confirmed if you manually order the items in the category ZZZZ > tab items
  • as far as I can see (not entirely sure) this still does not fix #73644

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 4

  1. Benni Mack commented and changed status New Closed <span data-processor="relativetime" data-value="2026-10-13T12:53:57+00:00" > 10/13/26, 12:53 </span>

    Closing together with #89474, which has the full explanation: the count in sys_category.items is only written when the category record itself is saved. It is meaningless as long as the Core API is used, because relations are always read from sys_category_record_mm, and the column may be removed in a future major version.

    That also explains the seemingly random values in your test series: the column shows the count from the last time the category was saved, not the current state.