MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _PropRegistry

Class _PropRegistry

lib/sqlalchemy/orm/path_registry.py:522–658  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520
521
522class _PropRegistry(PathRegistry):
523 __slots__ = (
524 "prop",
525 "parent",
526 "path",
527 "natural_path",
528 "has_entity",
529 "entity",
530 "mapper",
531 "_wildcard_path_loader_key",
532 "_default_path_loader_key",
533 "_loader_key",
534 "is_unnatural",
535 )
536 inherit_cache = True
537 is_property = True
538
539 prop: StrategizedProperty[Any]
540 mapper: Optional[Mapper[Any]]
541 entity: Optional[_InternalEntityType[Any]]
542
543 def __init__(
544 self, parent: _AbstractEntityRegistry, prop: StrategizedProperty[Any]
545 ):
546
547 # restate this path in terms of the
548 # given StrategizedProperty's parent.
549 insp = cast("_InternalEntityType[Any]", parent[-1])
550 natural_parent: _AbstractEntityRegistry = parent
551
552 # inherit "is_unnatural" from the parent
553 self.is_unnatural = parent.parent.is_unnatural or bool(
554 parent.mapper.inherits
555 )
556
557 if not insp.is_aliased_class or insp._use_mapper_path: # type: ignore
558 parent = natural_parent = parent.parent[prop.parent]
559 elif (
560 insp.is_aliased_class
561 and insp.with_polymorphic_mappers
562 and prop.parent in insp.with_polymorphic_mappers
563 ):
564 subclass_entity: _InternalEntityType[Any] = parent[-1]._entity_for_mapper(prop.parent) # type: ignore # noqa: E501
565 parent = parent.parent[subclass_entity]
566
567 # when building a path where with_polymorphic() is in use,
568 # special logic to determine the "natural path" when subclass
569 # entities are used.
570 #
571 # here we are trying to distinguish between a path that starts
572 # on a with_polymorphic entity vs. one that starts on a
573 # normal entity that introduces a with_polymorphic() in the
574 # middle using of_type():
575 #
576 # # as in test_polymorphic_rel->
577 # # test_subqueryload_on_subclass_uses_path_correctly
578 # wp = with_polymorphic(RegularEntity, "*")
579 # sess.query(wp).options(someload(wp.SomeSubEntity.foos))

Callers 2

_getitemMethod · 0.85
__missing__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected