diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 848fd6e..acd1ff9 100644
a
|
b
|
class ForeignRelatedObjectsDescriptor(object):
|
458 | 458 | return self.instance._prefetched_objects_cache[rel_field.related_query_name()] |
459 | 459 | except (AttributeError, KeyError): |
460 | 460 | db = self._db or router.db_for_read(self.model, instance=self.instance) |
| 461 | if getattr(self.instance, attname) is None: |
| 462 | return super(RelatedManager, self).get_query_set().using(db).none() |
461 | 463 | return super(RelatedManager, self).get_query_set().using(db).filter(**self.core_filters) |
462 | 464 | |
463 | 465 | def get_prefetch_query_set(self, instances): |
diff --git a/tests/regressiontests/many_to_one_regress/tests.py b/tests/regressiontests/many_to_one_regress/tests.py
index 9e04fb4..8c91723 100644
a
|
b
|
class ManyToOneRegressionTests(TestCase):
|
106 | 106 | # of a model, and interrogate its related field. |
107 | 107 | cat = models.ForeignKey(Category) |
108 | 108 | self.assertEqual('id', cat.rel.get_related_field().name) |
| 109 | |
| 110 | def test_related_relation_on_none(self): |
| 111 | # Test that the <field>_set manager does not join on Null value fields (#17541) |
| 112 | Third.objects.create(name='Third 1') |
| 113 | Third.objects.create(name='Third 2') |
| 114 | th = Third(name="testing") |
| 115 | self.assertEqual(th.child_set.count(), 0) |