(
self, parenttable: Table, table: Table, colname: Optional[str]
)
| 3439 | return parenttable, tablekey, colname |
| 3440 | |
| 3441 | def _link_to_col_by_colstring( |
| 3442 | self, parenttable: Table, table: Table, colname: Optional[str] |
| 3443 | ) -> Column[Any]: |
| 3444 | _column = None |
| 3445 | if colname is None: |
| 3446 | # colname is None in the case that ForeignKey argument |
| 3447 | # was specified as table name only, in which case we |
| 3448 | # match the column name to the same column on the |
| 3449 | # parent. |
| 3450 | # this use case wasn't working in later 1.x series |
| 3451 | # as it had no test coverage; fixed in 2.0 |
| 3452 | parent = self.parent |
| 3453 | assert parent is not None |
| 3454 | key = parent.key |
| 3455 | _column = table.c.get(key, None) |
| 3456 | elif self.link_to_name: |
| 3457 | key = colname |
| 3458 | for c in table.c: |
| 3459 | if c.name == colname: |
| 3460 | _column = c |
| 3461 | else: |
| 3462 | key = colname |
| 3463 | _column = table.c.get(colname, None) |
| 3464 | |
| 3465 | if _column is None: |
| 3466 | raise exc.NoReferencedColumnError( |
| 3467 | "Could not initialize target column " |
| 3468 | f"for ForeignKey '{self._get_colspec()}' " |
| 3469 | f"on table '{parenttable.name}': " |
| 3470 | f"table '{table.name}' has no column named '{key}'", |
| 3471 | table.name, |
| 3472 | key, |
| 3473 | ) |
| 3474 | |
| 3475 | return _column |
| 3476 | |
| 3477 | def _set_target_column(self, column: Column[Any]) -> None: |
| 3478 | assert self.parent is not None |
no test coverage detected