﻿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
17695	model grandchild joins to top instead of the middle first	phowe	nobody	"I create a blank app with these models:

{{{
class Base( models.Model ):
  b_id = models.AutoField( primary_key=True )
  b_desc = models.CharField( max_length=100 )

class Middle( Base ):
  m_id = models.AutoField( primary_key=True )
  m_desc = models.CharField( max_length=100 )

class Top( Middle ):
  t_id = models.AutoField( primary_key=True )
  t_desc = models.CharField( max_length=100 )

}}}


I run this:

{{{
d = Top.objects.all()
print d.query
SELECT ""example2_base"".""b_id"", ""example2_base"".""b_desc"", ""example2_middle"".""base_ptr_id"", ""example2_middle"".""m_id"", ""example2_middle"".""m_desc"", ""example2_top"".""middle_ptr_id"", ""example2_top"".""t_id"", ""example2_top"".""t_desc""
  FROM ""example2_top""
  INNER JOIN ""example2_base"" ON (""example2_top"".""middle_ptr_id"" = ""example2_base"".""b_id"")
  INNER JOIN ""example2_middle"" ON (""example2_top"".""middle_ptr_id"" = ""example2_middle"".""m_id"")
}}}


The INNER JOIN links the Base model to the Top, I would expect the joins to look like this:

{{{
 INNER JOIN ""example2_middle"" ON (""example2_top"".""middle_ptr_id"" = ""example2_middle"".""m_id"")
 INNER JOIN ""example2_base"" ON (""example2_middle"".""base_ptr_id"" = ""example2_base"".""b_id"")
}}}
 

As long as the id's in the 3 tables stay in sync, the issue is not noticed, however if one of the id's gets incremented a head of one of the others, the query returns the wrong base parts of the model.

I found this while running 1.2, I also downloaded the 1.4 alpha and noticed the same results."	Bug	closed	Database layer (models, ORM)	1.4-alpha-1	Normal	duplicate			Accepted	0	0	0	0	0	0
