MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / _fields_to_dbfields

Method _fields_to_dbfields

mongoengine/queryset/base.py:1909–1944  ·  view source on GitHub ↗

Translate fields' paths to their db equivalents.

(self, fields)

Source from the content-addressed store, hash-verified

1907 return frequencies
1908
1909 def _fields_to_dbfields(self, fields):
1910 """Translate fields' paths to their db equivalents."""
1911 subclasses = []
1912 if self._document._meta["allow_inheritance"]:
1913 subclasses = [get_document(x) for x in self._document._subclasses][1:]
1914
1915 db_field_paths = []
1916 for field in fields:
1917 field_parts = field.split(".")
1918 try:
1919 field = ".".join(
1920 f if isinstance(f, str) else f.db_field
1921 for f in self._document._lookup_field(field_parts)
1922 )
1923 db_field_paths.append(field)
1924 except LookUpError as err:
1925 found = False
1926
1927 # If a field path wasn't found on the main document, go
1928 # through its subclasses and see if it exists on any of them.
1929 for subdoc in subclasses:
1930 try:
1931 subfield = ".".join(
1932 f if isinstance(f, str) else f.db_field
1933 for f in subdoc._lookup_field(field_parts)
1934 )
1935 db_field_paths.append(subfield)
1936 found = True
1937 break
1938 except LookUpError:
1939 pass
1940
1941 if not found:
1942 raise err
1943
1944 return db_field_paths
1945
1946 def _get_order_by(self, keys):
1947 """Given a list of MongoEngine-style sort keys, return a list

Callers 4

distinctMethod · 0.95
sumMethod · 0.95
averageMethod · 0.95
fieldsMethod · 0.80

Calls 3

get_documentFunction · 0.90
joinMethod · 0.80
_lookup_fieldMethod · 0.80

Tested by

no test coverage detected