﻿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
18177	Discovering a relation should cache the originator if applicable	kaiser.yann@…	Aymeric Augustin	"Currently, related fields will not cache the originator object (which holds the field) into the returned objects. This patch makes reverse ForeignKey and OneToOneField relations cache the originator(s) into the queryset, and then in turn to the returned objects.

In example, it validates this test, with Pool objects having a ForeignKey to Tournament objects:

{{{
    def test_fk(self):
        with self.assertNumQueries(2):
            tournament = Tournament.objects.get(pk=1)
            pool = tournament.pool_set.all()[0]
            self.assertIs(tournament, pool.tournament)
}}}

Without this patch, the expression `pool.tournament` would trigger a third query and create a different instance. It also works with .prefetch_related() calls."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed	related, cache, ForeignKey, OneToOneField, prefetch_related		Ready for checkin	1	0	0	0	0	0
