eager DB fetching of nested objects

7 views
Skip to first unread message

Elico

unread,
Nov 26, 2019, 4:31:28 PM11/26/19
to django...@googlegroups.com
Hi,

I would like to query an object from a DB and fetch all nested objects.

For example:

class ModelA(models.Model):
    ...

class ModelB(models.Model):
    a = models.ForeignKey(ModelA)
    ...

class ModelC(models.Model):
    b = models.ForeignKey(ModelB)
    ...

I want to query C by it's ID and to eagerly fetch A and B:
ModelC.objects.filter(pk=id).select_related('b')

But how to I do it when I want to already fetch also a when I call c.b?

Thank you



Reply all
Reply to author
Forward
0 new messages