(
automap_base: Type[Any],
lcl_m2m: Table,
rem_m2m: Table,
m2m_const: List[ForeignKeyConstraint],
table: Table,
table_to_map_config: Union[
Dict[Optional[Table], _DeferredDeclarativeConfig],
Dict[Table, _DeferredDeclarativeConfig],
],
collection_class: type,
name_for_scalar_relationship: NameForCollectionRelationshipType,
name_for_collection_relationship: NameForCollectionRelationshipType,
generate_relationship: GenerateRelationshipType,
)
| 1600 | |
| 1601 | |
| 1602 | def _m2m_relationship( |
| 1603 | automap_base: Type[Any], |
| 1604 | lcl_m2m: Table, |
| 1605 | rem_m2m: Table, |
| 1606 | m2m_const: List[ForeignKeyConstraint], |
| 1607 | table: Table, |
| 1608 | table_to_map_config: Union[ |
| 1609 | Dict[Optional[Table], _DeferredDeclarativeConfig], |
| 1610 | Dict[Table, _DeferredDeclarativeConfig], |
| 1611 | ], |
| 1612 | collection_class: type, |
| 1613 | name_for_scalar_relationship: NameForCollectionRelationshipType, |
| 1614 | name_for_collection_relationship: NameForCollectionRelationshipType, |
| 1615 | generate_relationship: GenerateRelationshipType, |
| 1616 | ) -> None: |
| 1617 | map_config = table_to_map_config.get(lcl_m2m, None) |
| 1618 | referred_cfg = table_to_map_config.get(rem_m2m, None) |
| 1619 | if map_config is None or referred_cfg is None: |
| 1620 | return |
| 1621 | |
| 1622 | local_cls = map_config.cls |
| 1623 | referred_cls = referred_cfg.cls |
| 1624 | |
| 1625 | relationship_name = name_for_collection_relationship( |
| 1626 | automap_base, local_cls, referred_cls, m2m_const[0] |
| 1627 | ) |
| 1628 | backref_name = name_for_collection_relationship( |
| 1629 | automap_base, referred_cls, local_cls, m2m_const[1] |
| 1630 | ) |
| 1631 | |
| 1632 | create_backref = backref_name not in referred_cfg.properties |
| 1633 | |
| 1634 | if table in table_to_map_config: |
| 1635 | overlaps = "__*" |
| 1636 | else: |
| 1637 | overlaps = None |
| 1638 | |
| 1639 | if relationship_name not in map_config.properties: |
| 1640 | if create_backref: |
| 1641 | backref_obj = generate_relationship( |
| 1642 | automap_base, |
| 1643 | interfaces.MANYTOMANY, |
| 1644 | backref, |
| 1645 | backref_name, |
| 1646 | referred_cls, |
| 1647 | local_cls, |
| 1648 | collection_class=collection_class, |
| 1649 | overlaps=overlaps, |
| 1650 | ) |
| 1651 | else: |
| 1652 | backref_obj = None |
| 1653 | |
| 1654 | rel = generate_relationship( |
| 1655 | automap_base, |
| 1656 | interfaces.MANYTOMANY, |
| 1657 | relationship, |
| 1658 | relationship_name, |
| 1659 | local_cls, |
no test coverage detected