I'm new to django so please bear with me.
I have the below relationships. If I have the primary key of model A, how can I get all the data from A, B and C in the most efficient query?
Note: A -> C is a 1 to many relationship while B -> C is a many to one relationship (ie each C only has 1 B, but multiple Cs may have the same B).
I was thinking of some form of prefetch_related
but as I understand it, that implies I am making 3 db calls?
Also, is there somewhere I can see the SQL query that Django runs? I am using mysql as a db.
Class A(models.Model):
pass
Class B(models.Model):
pass
Class C(models.Model):
a = models.ForeignKey(A)
b = models.ForeignKey(B)