V
V
Vasyl Fomin2017-09-08 15:11:31
Laravel
Vasyl Fomin, 2017-09-08 15:11:31

How to build a query for pulling a tree structure like Feedback->Feedback-Response->Feedback-Response-to-Answer...->?

Hello! Faced the problem of building an sql-query to pull data from the database in the form of a tree structure.
It is possible to pull out the data, but I get a lot of requests.
Well, for example: there are articles on the site, and they have reviews (parent), while each review can have more reviews-answers (child), and these reviews have more, etc. Each review can also have several attached pictures (separate table).
All reviews are stored in one table: there are reviews without parents, and there are reviews with parents.
If you add childs to the $with array in the Answer model, then it turns out: there are so many requests:
39688f73a4f34bca895a6d519a9be6ff.png
And this is only for one answer with three levels of structure and without attached pictures I
use the Laravel framework to output the json array -laravel-fractal
I want to see examples, advice on how this is done at all..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2017-09-08
@fomvasss

it is necessary to select everything from the base, and then scatter the recursive function over the levels.
or google something like this
https://stackoverflow.com/questions/20215744/how-t...

U
UksusoFF, 2017-09-08
@UksusoFF

https://github.com/lazychaser/laravel-nestedset

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question