Split flatten tuple paths into ``select_related`` (single-valued FK, incl. self-ref) and ``prefetch_related`` (m2m / reverse) buckets so the caller can auto-add whichever the user hasn't loaded already. :param paths: pre-split tuple paths collected during flatten bu
(
self, paths: Iterable[tuple[str, ...]]
)
| 496 | ) |
| 497 | |
| 498 | def _classify_flatten_paths( |
| 499 | self, paths: Iterable[tuple[str, ...]] |
| 500 | ) -> tuple[set[str], set[str]]: |
| 501 | """ |
| 502 | Split flatten tuple paths into ``select_related`` (single-valued FK, |
| 503 | incl. self-ref) and ``prefetch_related`` (m2m / reverse) buckets so |
| 504 | the caller can auto-add whichever the user hasn't loaded already. |
| 505 | |
| 506 | :param paths: pre-split tuple paths collected during flatten build |
| 507 | :type paths: Iterable[tuple[str, ...]] |
| 508 | :return: (paths for select_related, paths for prefetch_related) — each |
| 509 | as dunder strings for downstream ``select_related`` / |
| 510 | ``prefetch_related`` call sites |
| 511 | :rtype: tuple[set[str], set[str]] |
| 512 | """ |
| 513 | select_paths: set[str] = set() |
| 514 | prefetch_paths: set[str] = set() |
| 515 | source_model = self.model |
| 516 | for parts in paths: |
| 517 | parent_model: type["Model"] = source_model |
| 518 | if len(parts) > 1: |
| 519 | _, parent_model, _, _ = get_relationship_alias_model_and_str( |
| 520 | source_model=source_model, |
| 521 | related_parts=list(parts[:-1]), |
| 522 | ) |
| 523 | field = parent_model.ormar_config.model_fields[parts[-1]] |
| 524 | bucket = ( |
| 525 | prefetch_paths |
| 526 | if getattr(field, "is_multi", False) or getattr(field, "virtual", False) |
| 527 | else select_paths |
| 528 | ) |
| 529 | bucket.add("__".join(parts)) |
| 530 | return select_paths, prefetch_paths |
| 531 | |
| 532 | def fields( |
| 533 | self, columns: Union[list, str, set, dict], slot: "Slot" = "include" |
no test coverage detected