MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _with_polymorphic_factory

Method _with_polymorphic_factory

lib/sqlalchemy/orm/util.py:1052–1089  ·  view source on GitHub ↗
(
        cls,
        base: Union[Type[_O], Mapper[_O]],
        classes: Union[Literal["*"], Iterable[_EntityType[Any]]],
        selectable: Union[Literal[False, None], FromClause] = False,
        flat: bool = False,
        polymorphic_on: Optional[ColumnElement[Any]] = None,
        aliased: bool = False,
        innerjoin: bool = False,
        adapt_on_names: bool = False,
        name: Optional[str] = None,
        _use_mapper_path: bool = False,
    )

Source from the content-addressed store, hash-verified

1050
1051 @classmethod
1052 def _with_polymorphic_factory(
1053 cls,
1054 base: Union[Type[_O], Mapper[_O]],
1055 classes: Union[Literal["*"], Iterable[_EntityType[Any]]],
1056 selectable: Union[Literal[False, None], FromClause] = False,
1057 flat: bool = False,
1058 polymorphic_on: Optional[ColumnElement[Any]] = None,
1059 aliased: bool = False,
1060 innerjoin: bool = False,
1061 adapt_on_names: bool = False,
1062 name: Optional[str] = None,
1063 _use_mapper_path: bool = False,
1064 ) -> AliasedClass[_O]:
1065 primary_mapper = _class_to_mapper(base)
1066
1067 if selectable not in (None, False) and flat:
1068 raise sa_exc.ArgumentError(
1069 "the 'flat' and 'selectable' arguments cannot be passed "
1070 "simultaneously to with_polymorphic()"
1071 )
1072
1073 mappers, selectable = primary_mapper._with_polymorphic_args(
1074 classes, selectable, innerjoin=innerjoin
1075 )
1076 if aliased or flat:
1077 assert selectable is not None
1078 selectable = selectable._anonymous_fromclause(flat=flat)
1079
1080 return AliasedClass(
1081 base,
1082 selectable,
1083 name=name,
1084 with_polymorphic_mappers=mappers,
1085 adapt_on_names=adapt_on_names,
1086 with_polymorphic_discriminator=polymorphic_on,
1087 use_mapper_path=_use_mapper_path,
1088 represents_outer_join=not innerjoin,
1089 )
1090
1091 @property
1092 def entity(self) -> AliasedClass[_O]:

Callers 2

_set_of_type_infoMethod · 0.80
with_polymorphicFunction · 0.80

Calls 4

_class_to_mapperFunction · 0.85
AliasedClassClass · 0.85
_anonymous_fromclauseMethod · 0.45

Tested by

no test coverage detected