MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _configure_inheritance

Method _configure_inheritance

lib/sqlalchemy/orm/mapper.py:1143–1324  ·  view source on GitHub ↗

Configure settings related to inheriting and/or inherited mappers being present.

(self)

Source from the content-addressed store, hash-verified

1141 return PathRegistry.per_mapper(self)
1142
1143 def _configure_inheritance(self):
1144 """Configure settings related to inheriting and/or inherited mappers
1145 being present."""
1146
1147 # a set of all mappers which inherit from this one.
1148 self._inheriting_mappers = util.WeakSequence()
1149
1150 if self.inherits:
1151 if not issubclass(self.class_, self.inherits.class_):
1152 raise sa_exc.ArgumentError(
1153 "Class '%s' does not inherit from '%s'"
1154 % (self.class_.__name__, self.inherits.class_.__name__)
1155 )
1156
1157 self.dispatch._update(self.inherits.dispatch)
1158
1159 if self.single:
1160 self.persist_selectable = self.inherits.persist_selectable
1161 elif self.local_table is not self.inherits.local_table:
1162 if self.concrete:
1163 self.persist_selectable = self.local_table
1164 for mapper in self.iterate_to_root():
1165 if mapper.polymorphic_on is not None:
1166 mapper._requires_row_aliasing = True
1167 else:
1168 if self.inherit_condition is None:
1169 # figure out inherit condition from our table to the
1170 # immediate table of the inherited mapper, not its
1171 # full table which could pull in other stuff we don't
1172 # want (allows test/inheritance.InheritTest4 to pass)
1173 try:
1174 self.inherit_condition = sql_util.join_condition(
1175 self.inherits.local_table, self.local_table
1176 )
1177 except sa_exc.NoForeignKeysError as nfe:
1178 assert self.inherits.local_table is not None
1179 assert self.local_table is not None
1180 raise sa_exc.NoForeignKeysError(
1181 "Can't determine the inherit condition "
1182 "between inherited table '%s' and "
1183 "inheriting "
1184 "table '%s'; tables have no "
1185 "foreign key relationships established. "
1186 "Please ensure the inheriting table has "
1187 "a foreign key relationship to the "
1188 "inherited "
1189 "table, or provide an "
1190 "'on clause' using "
1191 "the 'inherit_condition' mapper argument."
1192 % (
1193 self.inherits.local_table.description,
1194 self.local_table.description,
1195 )
1196 ) from nfe
1197 except sa_exc.AmbiguousForeignKeysError as afe:
1198 assert self.inherits.local_table is not None
1199 assert self.local_table is not None
1200 raise sa_exc.AmbiguousForeignKeysError(

Callers 1

__init__Method · 0.95

Calls 7

iterate_to_rootMethod · 0.95
to_setMethod · 0.80
_updateMethod · 0.45
joinMethod · 0.45
warnMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected