peopledoc/django-ltree-demo

Is `parent` field really needed?

amaury1093 opened this issue · 2 comments

parent = models.ForeignKey('self', null=True, related_name='children',
on_delete=models.CASCADE)

Am i correct in saying that this field is not actually needed, since with a materialized path you already have the whole path to the root? It's just convenience field for to get each node's parent/children?

k4nar commented

With this demo you don't construct the path "by hand" but let PostgreSQL construct it for you, only based on who the parent is. So you actually need to store the parent's ID in order to let the DB do its stuff :) .

If you don't mind managing the path by yourself then, indeed, you don't need to store the parent. You also don't need the SQL triggers.

Got it, thanks!