D
D
dllweb2014-10-09 19:55:06
MySQL
dllweb, 2014-10-09 19:55:06

How to create an unusual tree on twig symfony2?

Good day friends, the question is, we have tables
The end result looks like this
f23731d52acd413da0ce0c1a998de749.png
That is, in theory, we should link these 3 tables for output in this format, I want to emphasize that it is in this format that records should be output as shown in the example. If we select these tables from the database in conjunction with a double join, for example

SELECT Category.id catid, Category.name catname, Model.id modid, Model.name modelname, Model.small_img simg from Category 

left join ModelCategory on(ModelCategory.category_id = Category.id) 
left join Model on(ModelCategory.model_id = Model.id)

Then we, in principle, will get what we need, but the names of the categories will be duplicated, what needs to be done, or how to do it right, explain to the ignorant, but please, you don’t need to offer a crutch in the form of numerous requests to the database, thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-10-09
Protko @Fesor

Do you use Doctrine ORM? If you want native sql, then look towards named queries and aggregate data into DTOs as you wish. Then give this very DTO with all the data to twig, where you display it as you want. The trick will be that at the named querie level, we will transform the data structure into the one that our application wants to receive. And the rest of the application will not worry about the form in which this good is stored in the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question