| 1459 | |
| 1460 | |
| 1461 | def _is_many_to_many( |
| 1462 | automap_base: Type[Any], table: Table |
| 1463 | ) -> Tuple[ |
| 1464 | Optional[Table], Optional[Table], Optional[list[ForeignKeyConstraint]] |
| 1465 | ]: |
| 1466 | fk_constraints = [ |
| 1467 | const |
| 1468 | for const in table.constraints |
| 1469 | if isinstance(const, ForeignKeyConstraint) |
| 1470 | ] |
| 1471 | if len(fk_constraints) != 2: |
| 1472 | return None, None, None |
| 1473 | |
| 1474 | cols: List[Column[Any]] = sum( |
| 1475 | [ |
| 1476 | [fk.parent for fk in fk_constraint.elements] |
| 1477 | for fk_constraint in fk_constraints |
| 1478 | ], |
| 1479 | [], |
| 1480 | ) |
| 1481 | |
| 1482 | if set(cols) != set(table.c): |
| 1483 | return None, None, None |
| 1484 | |
| 1485 | return ( |
| 1486 | fk_constraints[0].elements[0].column.table, |
| 1487 | fk_constraints[1].elements[0].column.table, |
| 1488 | fk_constraints, |
| 1489 | ) |
| 1490 | |
| 1491 | |
| 1492 | def _relationships_for_fks( |