Configure settings related to inheriting and/or inherited mappers being present.
(self)
| 1197 | return PathRegistry.per_mapper(self) |
| 1198 | |
| 1199 | def _configure_inheritance(self): |
| 1200 | """Configure settings related to inheriting and/or inherited mappers |
| 1201 | being present.""" |
| 1202 | |
| 1203 | # a set of all mappers which inherit from this one. |
| 1204 | self._inheriting_mappers = util.WeakSequence() |
| 1205 | |
| 1206 | if self.inherits: |
| 1207 | if not issubclass(self.class_, self.inherits.class_): |
| 1208 | raise sa_exc.ArgumentError( |
| 1209 | "Class '%s' does not inherit from '%s'" |
| 1210 | % (self.class_.__name__, self.inherits.class_.__name__) |
| 1211 | ) |
| 1212 | |
| 1213 | self.dispatch._update(self.inherits.dispatch) |
| 1214 | |
| 1215 | if self.non_primary != self.inherits.non_primary: |
| 1216 | np = not self.non_primary and "primary" or "non-primary" |
| 1217 | raise sa_exc.ArgumentError( |
| 1218 | "Inheritance of %s mapper for class '%s' is " |
| 1219 | "only allowed from a %s mapper" |
| 1220 | % (np, self.class_.__name__, np) |
| 1221 | ) |
| 1222 | |
| 1223 | if self.single: |
| 1224 | self.persist_selectable = self.inherits.persist_selectable |
| 1225 | elif self.local_table is not self.inherits.local_table: |
| 1226 | if self.concrete: |
| 1227 | self.persist_selectable = self.local_table |
| 1228 | for mapper in self.iterate_to_root(): |
| 1229 | if mapper.polymorphic_on is not None: |
| 1230 | mapper._requires_row_aliasing = True |
| 1231 | else: |
| 1232 | if self.inherit_condition is None: |
| 1233 | # figure out inherit condition from our table to the |
| 1234 | # immediate table of the inherited mapper, not its |
| 1235 | # full table which could pull in other stuff we don't |
| 1236 | # want (allows test/inheritance.InheritTest4 to pass) |
| 1237 | try: |
| 1238 | self.inherit_condition = sql_util.join_condition( |
| 1239 | self.inherits.local_table, self.local_table |
| 1240 | ) |
| 1241 | except sa_exc.NoForeignKeysError as nfe: |
| 1242 | assert self.inherits.local_table is not None |
| 1243 | assert self.local_table is not None |
| 1244 | raise sa_exc.NoForeignKeysError( |
| 1245 | "Can't determine the inherit condition " |
| 1246 | "between inherited table '%s' and " |
| 1247 | "inheriting " |
| 1248 | "table '%s'; tables have no " |
| 1249 | "foreign key relationships established. " |
| 1250 | "Please ensure the inheriting table has " |
| 1251 | "a foreign key relationship to the " |
| 1252 | "inherited " |
| 1253 | "table, or provide an " |
| 1254 | "'on clause' using " |
| 1255 | "the 'inherit_condition' mapper argument." |
| 1256 | % ( |
no test coverage detected