MCPcopy
hub / github.com/django/django / table_alias

Method table_alias

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

Return a table alias for the given table_name and whether this is a new alias or not. If 'create' is true, a new alias is always created. Otherwise, the most recently created alias for the table (if one exists) is reused.

(self, table_name, create=False, filtered_relation=None)

Source from the content-addressed store, hash-verified

897 return self._get_only_select_mask(opts, mask)
898
899 def table_alias(self, table_name, create=False, filtered_relation=None):
900 """
901 Return a table alias for the given table_name and whether this is a
902 new alias or not.
903
904 If 'create' is true, a new alias is always created. Otherwise, the
905 most recently created alias for the table (if one exists) is reused.
906 """
907 alias_list = self.table_map.get(table_name)
908 if not create and alias_list:
909 alias = alias_list[0]
910 self.alias_refcount[alias] += 1
911 return alias, False
912
913 # Create a new alias for this table.
914 if alias_list:
915 alias = "%s%d" % (self.alias_prefix, len(self.alias_map) + 1)
916 alias_list.append(alias)
917 else:
918 # The first occurrence of a table uses the table name directly.
919 alias = (
920 filtered_relation.alias if filtered_relation is not None else table_name
921 )
922 self.table_map[table_name] = [alias]
923 self.alias_refcount[alias] = 1
924 return alias, True
925
926 def ref_alias(self, alias):
927 """Increases the reference count for this alias."""

Callers 2

joinMethod · 0.95
get_from_clauseMethod · 0.80

Calls 2

getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected