MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _joincond_trim_constraints

Method _joincond_trim_constraints

lib/sqlalchemy/sql/selectable.py:1596–1628  ·  view source on GitHub ↗
(
        cls,
        a: FromClause,
        b: FromClause,
        constraints: Dict[Any, Any],
        consider_as_foreign_keys: Optional[Any],
    )

Source from the content-addressed store, hash-verified

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(

Callers 1

_join_conditionMethod · 0.80

Calls 1

valuesMethod · 0.45

Tested by

no test coverage detected