MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _set_table

Method _set_table

lib/sqlalchemy/sql/schema.py:3278–3322  ·  view source on GitHub ↗
(self, column: Column[Any], table: Table)

Source from the content-addressed store, hash-verified

3276 metadata._fk_memos[fk_key].remove(self)
3277
3278 def _set_table(self, column: Column[Any], table: Table) -> None:
3279 # standalone ForeignKey - create ForeignKeyConstraint
3280 # on the hosting Table when attached to the Table.
3281 assert isinstance(table, Table)
3282 if self.constraint is None:
3283 self.constraint = ForeignKeyConstraint(
3284 [],
3285 [],
3286 use_alter=self.use_alter,
3287 name=self.name,
3288 onupdate=self.onupdate,
3289 ondelete=self.ondelete,
3290 deferrable=self.deferrable,
3291 initially=self.initially,
3292 match=self.match,
3293 comment=self.comment,
3294 **self._unvalidated_dialect_kw,
3295 )
3296 self.constraint._append_element(column, self)
3297 self.constraint._set_parent_with_dispatch(table)
3298 table.foreign_keys.add(self)
3299 # set up remote ".column" attribute, or a note to pick it
3300 # up when the other Table/Column shows up
3301 if isinstance(self._colspec, str):
3302 parenttable, table_key, colname = self._resolve_col_tokens()
3303 fk_key = (table_key, colname)
3304 if table_key in parenttable.metadata.tables:
3305 table = parenttable.metadata.tables[table_key]
3306 try:
3307 _column = self._link_to_col_by_colstring(
3308 parenttable, table, colname
3309 )
3310 except exc.NoReferencedColumnError:
3311 # this is OK, we'll try later
3312 pass
3313 else:
3314 self._set_target_column(_column)
3315
3316 parenttable.metadata._fk_memos[fk_key].append(self)
3317 elif hasattr(self._colspec, "__clause_element__"):
3318 _column = self._colspec.__clause_element__()
3319 self._set_target_column(_column)
3320 else:
3321 _column = self._colspec
3322 self._set_target_column(_column)
3323
3324
3325if TYPE_CHECKING:

Callers

nothing calls this directly

Calls 9

_resolve_col_tokensMethod · 0.95
_set_target_columnMethod · 0.95
_append_elementMethod · 0.80
addMethod · 0.45
appendMethod · 0.45
__clause_element__Method · 0.45

Tested by

no test coverage detected