MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _join_condition

Method _join_condition

lib/sqlalchemy/sql/selectable.py:1420–1462  ·  view source on GitHub ↗

Create a join condition between two tables or selectables. See sqlalchemy.sql.util.join_condition() for full docs.

(
        cls,
        a: FromClause,
        b: FromClause,
        *,
        a_subset: Optional[FromClause] = None,
        consider_as_foreign_keys: Optional[
            AbstractSet[ColumnClause[Any]]
        ] = None,
    )

Source from the content-addressed store, hash-verified

1418
1419 @classmethod
1420 def _join_condition(
1421 cls,
1422 a: FromClause,
1423 b: FromClause,
1424 *,
1425 a_subset: Optional[FromClause] = None,
1426 consider_as_foreign_keys: Optional[
1427 AbstractSet[ColumnClause[Any]]
1428 ] = None,
1429 ) -> ColumnElement[bool]:
1430 """Create a join condition between two tables or selectables.
1431
1432 See sqlalchemy.sql.util.join_condition() for full docs.
1433
1434 """
1435 constraints = cls._joincond_scan_left_right(
1436 a, a_subset, b, consider_as_foreign_keys
1437 )
1438
1439 if len(constraints) > 1:
1440 cls._joincond_trim_constraints(
1441 a, b, constraints, consider_as_foreign_keys
1442 )
1443
1444 if len(constraints) == 0:
1445 if isinstance(b, FromGrouping):
1446 hint = (
1447 " Perhaps you meant to convert the right side to a "
1448 "subquery using alias()?"
1449 )
1450 else:
1451 hint = ""
1452 raise exc.NoForeignKeysError(
1453 "Can't find any foreign key relationships "
1454 "between '%s' and '%s'.%s"
1455 % (a.description, b.description, hint)
1456 )
1457
1458 crit = [(x == y) for x, y in list(constraints.values())[0]]
1459 if len(crit) == 1:
1460 return crit[0]
1461 else:
1462 return and_(*crit)
1463
1464 @classmethod
1465 def _can_join(

Callers 2

_match_primariesMethod · 0.95
join_conditionFunction · 0.80

Calls 4

and_Function · 0.85
valuesMethod · 0.45

Tested by

no test coverage detected