MCPcopy Index your code
hub / github.com/tortoise/tortoise-orm / _resolve_annotate

Method _resolve_annotate

tortoise/queryset.py:272–296  ·  view source on GitHub ↗
(self, fields_for_select: Collection[str] | None = None)

Source from the content-addressed store, hash-verified

270 self.query = self.query.orderby(field, order=ordering[1])
271
272 def _resolve_annotate(self, fields_for_select: Collection[str] | None = None) -> bool:
273 if not self._annotations:
274 return False
275
276 annotation_info: dict[str, ResolveResult] = {}
277 for key, annotation in self._annotations.items():
278 if isinstance(annotation, Term):
279 annotation_info[key] = ResolveResult(term=annotation)
280 else:
281 annotation_info[key] = annotation.resolve(
282 ResolveContext(
283 model=self.model,
284 table=self.model._meta.basetable,
285 annotations=self._annotations,
286 custom_filters=self._custom_filters,
287 )
288 )
289
290 for key, info in annotation_info.items():
291 for join in info.joins:
292 self._join_table(join)
293 if key in self._annotations and (fields_for_select is None or key in fields_for_select):
294 self.query._select_other(info.term.as_(key)) # type:ignore[arg-type]
295
296 return any(info.term.is_aggregate for info in annotation_info.values())
297
298 def sql(self, params_inline=False) -> str:
299 """

Callers 1

resolve_filtersMethod · 0.95

Calls 7

_join_tableMethod · 0.95
ResolveResultClass · 0.90
ResolveContextClass · 0.90
itemsMethod · 0.80
as_Method · 0.80
resolveMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected