first implementation of the recursive search for related entities