MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _joincond_scan_left_right

Method _joincond_scan_left_right

lib/sqlalchemy/sql/selectable.py:1527–1593  ·  view source on GitHub ↗
(
        cls,
        a: FromClause,
        a_subset: Optional[FromClause],
        b: FromClause,
        consider_as_foreign_keys: Optional[AbstractSet[ColumnClause[Any]]],
    )

Source from the content-addressed store, hash-verified

1525 @classmethod
1526 @util.preload_module("sqlalchemy.sql.util")
1527 def _joincond_scan_left_right(
1528 cls,
1529 a: FromClause,
1530 a_subset: Optional[FromClause],
1531 b: FromClause,
1532 consider_as_foreign_keys: Optional[AbstractSet[ColumnClause[Any]]],
1533 ) -> collections.defaultdict[
1534 Optional[ForeignKeyConstraint],
1535 List[Tuple[ColumnClause[Any], ColumnClause[Any]]],
1536 ]:
1537 sql_util = util.preloaded.sql_util
1538
1539 a = coercions.expect(roles.FromClauseRole, a)
1540 b = coercions.expect(roles.FromClauseRole, b)
1541
1542 constraints: collections.defaultdict[
1543 Optional[ForeignKeyConstraint],
1544 List[Tuple[ColumnClause[Any], ColumnClause[Any]]],
1545 ] = collections.defaultdict(list)
1546
1547 for left in (a_subset, a):
1548 if left is None:
1549 continue
1550 for fk in sorted(
1551 b.foreign_keys,
1552 key=lambda fk: fk.parent._creation_order,
1553 ):
1554 if (
1555 consider_as_foreign_keys is not None
1556 and fk.parent not in consider_as_foreign_keys
1557 ):
1558 continue
1559 try:
1560 col = fk.get_referent(left)
1561 except exc.NoReferenceError as nrte:
1562 table_names = {t.name for t in sql_util.find_tables(left)}
1563 if nrte.table_name in table_names:
1564 raise
1565 else:
1566 continue
1567
1568 if col is not None:
1569 constraints[fk.constraint].append((col, fk.parent))
1570 if left is not b:
1571 for fk in sorted(
1572 left.foreign_keys,
1573 key=lambda fk: fk.parent._creation_order,
1574 ):
1575 if (
1576 consider_as_foreign_keys is not None
1577 and fk.parent not in consider_as_foreign_keys
1578 ):
1579 continue
1580 try:
1581 col = fk.get_referent(b)
1582 except exc.NoReferenceError as nrte:
1583 table_names = {t.name for t in sql_util.find_tables(b)}
1584 if nrte.table_name in table_names:

Callers 2

_join_conditionMethod · 0.80
_can_joinMethod · 0.80

Calls 2

get_referentMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected