D
D
Danil Chekalin2014-05-04 20:53:04
MySQL
Danil Chekalin, 2014-05-04 20:53:04

How to change order in Adjacency list model?

I implement my tree with dnd on backbone + marionette. Backend - Laravel.
Structure in the database and filling:
56a0f870c3da4749a725161edf68769b.jpg
How it looks on the frontend:
2d0307c6432d42ad9284065bc504e830.jpg
At the moment, there is no field responsible for the order in the database.
Interested in the implementation of reordering on the backend side. The only option that comes to mind is:
for example, we take a branch (I will immediately indicate the values ​​\u200b\u200bof the order (rank, sort - whatever) field in square brackets)
- Itaque a veritatis. [1]
- - Node 3 - 1 [1]
- - Node 3 - 2 [2]
- - Node 3 - 3 [3]
- - Node 3 - 4 [4]
And we want to drag Node 3 - 4 to a position before Node 3 - 1. We set Node 3 -1 order equal to 1, and for all subsequent nodes we recalculate order + 1. But here the question arises, what if there are many nodes at the same level. In general, I do not know how to approach this issue.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Solovyov, 2014-05-16
@dakiesse

for trees you need to use nested set devacademy.ru/posts/nested-set

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question