Self-referencing (hierarchical) fields not available in Template Print

Hi team,

We’re currently using NocoBase to build an evaluation system with hierarchical data, and we’ve run into a limitation with the Template Print feature.


:jigsaw: Our Data Model

We have a self-referencing structure in the tests collection:

  • A test can have sub-tests using a self-referencing field:

    • tests.parent_test_id → tests.id

Example:

  • Shooting (parent test)

    • Accuracy (sub-test)
    • Speed (sub-test)

:page_facing_up: Use Case (Template Print)

We are trying to generate printable reports (using Template Print) that show:

  • Parent test (e.g., Shooting)
  • Its sub-tests (Accuracy, Speed)
  • Scores for each

Expected output structure:

Shooting: 21 / 30
  - Accuracy: 12 / 15
  - Speed: 9 / 15

Fitness: 18 / 20

:x: Problem

In Template Print:

  • Self-referencing relations (like sub_tests or parent_test) are not visible in the field selector
  • Only direct fields and simple relations are shown
  • There is no way to traverse or loop through hierarchical child records

This prevents us from:

  • Rendering sub-tests under a parent test
  • Building nested layouts in the print template
  • Accessing child records dynamically

:mag: Observations

  • Regular relations (e.g., belongsTo, hasMany) work fine when they are between different collections
  • However, self-referencing relations are not exposed in Template Print UI
  • Even when the relation exists and is populated in data, it is not selectable

:dart: Expected Behavior

We expect Template Print to support:

  1. Self-referencing relations in field list

    • Example: tests.sub_tests
  2. Nested rendering / iteration

    • Ability to loop through child records inside a parent block
  3. Multi-level traversal

    • Parent → child → grandchild (if needed)

:boom: Impact

This limitation affects:

  • Printable evaluation reports
  • Score breakdown visibility
  • Any hierarchical reporting use case

:pray: Request

Can you please confirm:

  • Whether this is a known limitation?
  • If there is a workaround?
  • If support for self-referencing relations in Template Print is planned?

Happy to share sample schema or data if needed.

Nocobase Version - 2.0.17

Thanks!

@hongboji - Any insights into this issue?

Thank you for reporting the issue. Please wait while we fix it.

1 Like

Until the fix lands, one workaround is to keep the self relation out of the print path. You already noticed that hasMany between two different collections shows up fine in Template Print, so you can split the data that way:

  1. Create a sub_tests collection (name, score, max_score) with a many to one field back to tests.
  2. On tests, add the reverse one to many field, sub_tests.
  3. Move the existing child rows into it with an export and import that keeps the parent id.
  4. In the template, loop the children under each parent:
    {d.sub_tests[i].name}: {d.sub_tests[i].score} / {d.sub_tests[i].max_score}
    {d.sub_tests[i+1]}

If you print the whole evaluation, nest the loop inside the loop over tests ({d.tests[i].sub_tests[j].name} and so on).

For the parent line (Shooting: 21 / 30), store the totals as fields on tests and fill them with a workflow that sums the children on save, so the template only prints values.

This is only worth the migration if you can’t wait for the fix.

(Disclosure: I’m connected to thirds.ai.)