murze
murze

Reputation: 4103

What is the best way to add and order to Doctrine Nested Set Trees?

What is the best way to add a sense of order in Doctrine Nested Sets?

The documention contains several examples of how to get al the childeren of a specific node

$category->getNode()->getSiblings()

But how can I for example:

Do I have to manually add and ordercolumn to the model to do these operations?

Upvotes: 0

Views: 1119

Answers (1)

reko_t
reko_t

Reputation: 56430

To get the second previous sibling:

$anotherCategory = $category->getNode()->getPrevSibling()->getNode()->getPrevSibling();

To insert category in its place:

$category->getNode()->moveAsPrevSiblingOf($anotherCategory);

To add a new sibling between second and third child, you'd simply use insertAsNextSiblingOf instead of moveAsPrevSiblingOf.

Upvotes: 1

Related Questions