From 00f0b0d233e4197227d05cb1fe55855100d415ad Mon Sep 17 00:00:00 2001 From: VIZZARD-X Date: Sat, 22 Nov 2025 12:05:35 +0530 Subject: [6.0.x] Fixed #29762 -- Doc'd how database routers fetch related objects. Thanks James Bligh for the review. Co-authored-by: Jacob Walls Backport of edd899786851f6285abbc3c272f4f5ec0e48a74c from main. --- docs/topics/db/multi-db.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/topics/db/multi-db.txt b/docs/topics/db/multi-db.txt index 38f91c2800..5e423d4981 100644 --- a/docs/topics/db/multi-db.txt +++ b/docs/topics/db/multi-db.txt @@ -232,6 +232,12 @@ cases, no instance hint will be provided at all. The router checks for the existence of an instance hint, and determine if that hint should be used to alter routing behavior. +If an ``instance`` hint is present, the database from which it was fetched +is recorded on its :attr:`instance._state.db `. +Routers will need to first consult that attribute before falling back to any +fixed alias to match Django's default behavior of fetching related instances +from the same database. + Using routers ------------- -- cgit v1.3