MCPcopy
hub / github.com/django/django / join_parent_model

Method join_parent_model

django/db/models/sql/query.py:1188–1219  ·  view source on GitHub ↗

Make sure the given 'model' is joined in the query. If 'model' isn't a parent of 'opts' or if it is None this method is a no-op. The 'alias' is the root alias for starting the join, 'seen' is a dict of model -> alias of existing joins. It must also contain a mapping

(self, opts, model, alias, seen)

Source from the content-addressed store, hash-verified

1186 return alias
1187
1188 def join_parent_model(self, opts, model, alias, seen):
1189 """
1190 Make sure the given 'model' is joined in the query. If 'model' isn't
1191 a parent of 'opts' or if it is None this method is a no-op.
1192
1193 The 'alias' is the root alias for starting the join, 'seen' is a dict
1194 of model -> alias of existing joins. It must also contain a mapping
1195 of None -> some alias. This will be returned in the no-op case.
1196 """
1197 if model in seen:
1198 return seen[model]
1199 chain = opts.get_base_chain(model)
1200 if not chain:
1201 return alias
1202 curr_opts = opts
1203 for int_model in chain:
1204 if int_model in seen:
1205 curr_opts = int_model._meta
1206 alias = seen[int_model]
1207 continue
1208 # Proxy model have elements in base chain
1209 # with no parents, assign the new options
1210 # object and skip to the next base in that
1211 # case
1212 if not curr_opts.parents[int_model]:
1213 curr_opts = int_model._meta
1214 continue
1215 link_field = curr_opts.get_ancestor_link(int_model)
1216 join_info = self.setup_joins([link_field.name], curr_opts, alias)
1217 curr_opts = int_model._meta
1218 alias = seen[int_model] = join_info.joins[-1]
1219 return alias or seen[None]
1220
1221 def check_alias(self, alias):
1222 # RemovedInDjango70Warning: When the deprecation ends, remove.

Callers 1

get_default_columnsMethod · 0.80

Calls 3

setup_joinsMethod · 0.95
get_base_chainMethod · 0.80
get_ancestor_linkMethod · 0.80

Tested by

no test coverage detected