﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
3045	Django hangs up when select_related() on cross-related models	Brut[all]	Adrian Holovaty	"Sometimes we need to relate X to Y and Y to X simultaneously.
For example if objects Y belongs to objects X and each X has a ""main"" Y (a man has fifteen women, but only one is his wife).

We could write something like this:

class man(models.Model):
    wife = models.ForeignKey('woman') # or OneToOneField - for some reason ForeignKey fits here better for me

class woman(models.Model):
    man = models.ForeignKey(man)

, but if we then select_related() women, Django hangs on creating SQL query.
It tries (as I think) to join men to women, then women to joined men, men to women again and so on - it loops infinitively.

I think, there should be a field option, which will tell Django to no select_related() in this direction. Something like stop_select_related=True - False in default, of course.
And Django should look for cross-relationships before it starts making a query in select_related() - to throw a exception instead of simply hangs up :-)


Sorry for my poor english :-)"	defect	closed	Database layer (models, ORM)	dev	normal	duplicate	select_related cross-relationships		Unreviewed	0	0	0	0	0	0
