given a with_polymorphic() argument, return the set of mappers it represents. Trims the list of mappers to just those represented within the given selectable, if present. This helps some more legacy-ish mappings.
(
self, spec: Any, selectable: Optional[FromClause]
)
| 2500 | return iter(self._props.values()) |
| 2501 | |
| 2502 | def _mappers_from_spec( |
| 2503 | self, spec: Any, selectable: Optional[FromClause] |
| 2504 | ) -> Sequence[Mapper[Any]]: |
| 2505 | """given a with_polymorphic() argument, return the set of mappers it |
| 2506 | represents. |
| 2507 | |
| 2508 | Trims the list of mappers to just those represented within the given |
| 2509 | selectable, if present. This helps some more legacy-ish mappings. |
| 2510 | |
| 2511 | """ |
| 2512 | if spec == "*": |
| 2513 | mappers = list(self.self_and_descendants) |
| 2514 | elif spec: |
| 2515 | mapper_set: Set[Mapper[Any]] = set() |
| 2516 | for m in util.to_list(spec): |
| 2517 | m = _class_to_mapper(m) |
| 2518 | if not m.isa(self): |
| 2519 | raise sa_exc.InvalidRequestError( |
| 2520 | "%r does not inherit from %r" % (m, self) |
| 2521 | ) |
| 2522 | |
| 2523 | if selectable is None: |
| 2524 | mapper_set.update(m.iterate_to_root()) |
| 2525 | else: |
| 2526 | mapper_set.add(m) |
| 2527 | mappers = [m for m in self.self_and_descendants if m in mapper_set] |
| 2528 | else: |
| 2529 | mappers = [] |
| 2530 | |
| 2531 | if selectable is not None: |
| 2532 | tables = set( |
| 2533 | sql_util.find_tables(selectable, include_aliases=True) |
| 2534 | ) |
| 2535 | mappers = [m for m in mappers if m.local_table in tables] |
| 2536 | return mappers |
| 2537 | |
| 2538 | def _selectable_from_mappers( |
| 2539 | self, mappers: Iterable[Mapper[Any]], innerjoin: bool |