| 1594 | |
| 1595 | @classmethod |
| 1596 | def _joincond_trim_constraints( |
| 1597 | cls, |
| 1598 | a: FromClause, |
| 1599 | b: FromClause, |
| 1600 | constraints: Dict[Any, Any], |
| 1601 | consider_as_foreign_keys: Optional[Any], |
| 1602 | ) -> None: |
| 1603 | # more than one constraint matched. narrow down the list |
| 1604 | # to include just those FKCs that match exactly to |
| 1605 | # "consider_as_foreign_keys". |
| 1606 | if consider_as_foreign_keys: |
| 1607 | for const in list(constraints): |
| 1608 | if {f.parent for f in const.elements} != set( |
| 1609 | consider_as_foreign_keys |
| 1610 | ): |
| 1611 | del constraints[const] |
| 1612 | |
| 1613 | # if still multiple constraints, but |
| 1614 | # they all refer to the exact same end result, use it. |
| 1615 | if len(constraints) > 1: |
| 1616 | dedupe = {tuple(crit) for crit in constraints.values()} |
| 1617 | if len(dedupe) == 1: |
| 1618 | key = list(constraints)[0] |
| 1619 | constraints = {key: constraints[key]} |
| 1620 | |
| 1621 | if len(constraints) != 1: |
| 1622 | raise exc.AmbiguousForeignKeysError( |
| 1623 | "Can't determine join between '%s' and '%s'; " |
| 1624 | "tables have more than one foreign key " |
| 1625 | "constraint relationship between them. " |
| 1626 | "Please specify the 'onclause' of this " |
| 1627 | "join explicitly." % (a.description, b.description) |
| 1628 | ) |
| 1629 | |
| 1630 | @overload |
| 1631 | def select( |