Hello all, I'm having problem with recursive query.
I have 3 models as seen below, Person relates to self using a through table and Company relates to Person with 1:1
My goal is to query Company and get its all people recursively without running n+1
class Person(models.Model):
name = models.CharField(max_length=50)
sub_people = models.ManyToManyField(
"self",
symmetrical=False,
through="PersonRelation",
through_fields=["child", "parent"]
)
class PersonRelation(models.Model):
child = models.ForeignKey(Person)
parent = models.ForeignKey(Person)
class Company(models.Model):
person = models.OneToOneField(Person)