Counting related relations in self-joint
I have a database with a bunch of documents. I'm attaching documents to each other in a simple self-joint relationship.
What I'm now interested in is to count the total sum of documents related to a given document.
The trick is that a given document might have 3 attached (self-related) documents and those documents might have additional attached (related) documents and so forth. I usually won't go deeper than 5 levels.
Is it possible to get a count of the number of all the related documents + their relations + their relations etc.?
I hope I'm expressing this clearly enough.
Thanks in advance (I have tried to search the forum for a similar issue but wasn't able to find it).