S
S
Sergey Shlensky2022-02-15 17:54:27
JavaScript
Sergey Shlensky, 2022-02-15 17:54:27

How to display category hierarchy?

I have two tables category and subcategories, I need to get the hierarchy using Spring Boot JPA to display on the page

Hierarchy Example

  • Category 1:
    • subcategory 2
    • subcategory 3

  • Category 2
    • subcategory 1
    • subcategory 4

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-02-28
@thewind

Maybe it doesn't reset? But it’s just that the number 10 appears there, but at the same time the style of the block is such that the unit becomes invisible?
That is, overflow and text-align:right

S
Slava Rozhnev, 2022-02-15
@seeyoga

You can aggregate data in DB like this:

SELECT 
  category.id, category.title, ARRAY_AGG(subcategory.title)
FROM category
JOIN subcategory ON subcategory.category_id = category.id
GROUP BY category.id, category.title;

PostgreSQL online ARRAY_AGG

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question