MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _mappers_from_spec

Method _mappers_from_spec

lib/sqlalchemy/orm/mapper.py:2502–2536  ·  view source on GitHub ↗

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]
    )

Source from the content-addressed store, hash-verified

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

Callers 10

test_ordered_b_dMethod · 0.80
test_aMethod · 0.80
test_b_d_selectableMethod · 0.80
test_d_selectableMethod · 0.80
test_reverse_d_bMethod · 0.80
test_d_b_missingMethod · 0.80
test_d_c_bMethod · 0.80

Calls 5

_class_to_mapperFunction · 0.85
isaMethod · 0.80
iterate_to_rootMethod · 0.80
updateMethod · 0.45
addMethod · 0.45

Tested by 7

test_ordered_b_dMethod · 0.64
test_aMethod · 0.64
test_b_d_selectableMethod · 0.64
test_d_selectableMethod · 0.64
test_reverse_d_bMethod · 0.64
test_d_b_missingMethod · 0.64
test_d_c_bMethod · 0.64