MCPcopy
hub / github.com/django/django / get_related_selections

Method get_related_selections

django/db/models/sql/compiler.py:1174–1405  ·  view source on GitHub ↗

Fill in the information needed for a select_related query. The current depth is measured as the number of connections away from the root model (for example, cur_depth=1 means we are looking at models with direct connections to the root model).

(
        self,
        select,
        select_mask,
        opts=None,
        root_alias=None,
        cur_depth=1,
        requested=None,
        restricted=None,
    )

Source from the content-addressed store, hash-verified

1172 return result, params
1173
1174 def get_related_selections(
1175 self,
1176 select,
1177 select_mask,
1178 opts=None,
1179 root_alias=None,
1180 cur_depth=1,
1181 requested=None,
1182 restricted=None,
1183 ):
1184 """
1185 Fill in the information needed for a select_related query. The current
1186 depth is measured as the number of connections away from the root model
1187 (for example, cur_depth=1 means we are looking at models with direct
1188 connections to the root model).
1189 """
1190
1191 def _get_field_choices():
1192 direct_choices = (f.name for f in opts.fields if f.is_relation)
1193 reverse_choices = (
1194 f.field.related_query_name()
1195 for f in opts.related_objects
1196 if f.field.unique
1197 )
1198 return chain(
1199 direct_choices, reverse_choices, self.query._filtered_relations
1200 )
1201
1202 related_klass_infos = []
1203 if not restricted and cur_depth > self.query.max_depth:
1204 # We've recursed far enough; bail out.
1205 return related_klass_infos
1206
1207 if not opts:
1208 opts = self.query.get_meta()
1209 root_alias = self.query.get_initial_alias()
1210
1211 # Setup for the case when only particular related fields should be
1212 # included in the related selection.
1213 fields_found = set()
1214 if requested is None:
1215 restricted = isinstance(self.query.select_related, dict)
1216 if restricted:
1217 requested = self.query.select_related
1218
1219 def get_related_klass_infos(klass_info, related_klass_infos):
1220 klass_info["related_klass_infos"] = related_klass_infos
1221
1222 for f in opts.fields:
1223 fields_found.add(f.name)
1224
1225 if restricted:
1226 next = requested.get(f.name, {})
1227 if not f.is_relation:
1228 # If a non-related field is used like a relation,
1229 # or if a single non-relational field is given.
1230 if next or f.name in requested:
1231 raise FieldError(

Callers 1

get_selectMethod · 0.95

Calls 12

get_default_columnsMethod · 0.95
FieldErrorClass · 0.90
select_related_descendFunction · 0.90
get_initial_aliasMethod · 0.80
setup_joinsMethod · 0.80
related_query_nameMethod · 0.80
get_metaMethod · 0.45
addMethod · 0.45
getMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45
differenceMethod · 0.45

Tested by

no test coverage detected