MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / join

Function join

lib/sqlalchemy/orm/_orm_constructors.py:2623–2678  ·  view source on GitHub ↗

r"""Produce an inner join between left and right clauses. :func:`_orm.join` is an extension to the core join interface provided by :func:`_expression.join()`, where the left and right selectable may be not only core selectable objects such as :class:`_schema.Table`, but also mapped

(
    left: _FromClauseArgument,
    right: _FromClauseArgument,
    onclause: Optional[_OnClauseArgument] = None,
    isouter: bool = False,
    full: bool = False,
)

Source from the content-addressed store, hash-verified

2621
2622
2623def join(
2624 left: _FromClauseArgument,
2625 right: _FromClauseArgument,
2626 onclause: Optional[_OnClauseArgument] = None,
2627 isouter: bool = False,
2628 full: bool = False,
2629) -> _ORMJoin:
2630 r"""Produce an inner join between left and right clauses.
2631
2632 :func:`_orm.join` is an extension to the core join interface
2633 provided by :func:`_expression.join()`, where the
2634 left and right selectable may be not only core selectable
2635 objects such as :class:`_schema.Table`, but also mapped classes or
2636 :class:`.AliasedClass` instances. The "on" clause can
2637 be a SQL expression or an ORM mapped attribute
2638 referencing a configured :func:`_orm.relationship`.
2639
2640 :func:`_orm.join` is not commonly needed in modern usage,
2641 as its functionality is encapsulated within that of the
2642 :meth:`_sql.Select.join` and :meth:`_query.Query.join`
2643 methods. which feature a
2644 significant amount of automation beyond :func:`_orm.join`
2645 by itself. Explicit use of :func:`_orm.join`
2646 with ORM-enabled SELECT statements involves use of the
2647 :meth:`_sql.Select.select_from` method, as in::
2648
2649 from sqlalchemy.orm import join
2650
2651 stmt = (
2652 select(User)
2653 .select_from(join(User, Address, User.addresses))
2654 .filter(Address.email_address == "foo@bar.com")
2655 )
2656
2657 In modern SQLAlchemy the above join can be written more
2658 succinctly as::
2659
2660 stmt = (
2661 select(User)
2662 .join(User.addresses)
2663 .filter(Address.email_address == "foo@bar.com")
2664 )
2665
2666 .. warning:: using :func:`_orm.join` directly may not work properly
2667 with modern ORM options such as :func:`_orm.with_loader_criteria`.
2668 It is strongly recommended to use the idiomatic join patterns
2669 provided by methods such as :meth:`.Select.join` and
2670 :meth:`.Select.join_from` when creating ORM joins.
2671
2672 .. seealso::
2673
2674 :ref:`orm_queryguide_joins` - in the :ref:`queryguide_toplevel` for
2675 background on idiomatic ORM join patterns
2676
2677 """
2678 return _ORMJoin(left, right, onclause, isouter, full)
2679
2680

Callers 15

test_seven_aMethod · 0.90
test_seven_bMethod · 0.90
test_seven_cMethod · 0.90
test_seven_dMethod · 0.90
test_joinsMethod · 0.90
test_full_outer_joinMethod · 0.90
goMethod · 0.90

Calls 1

_ORMJoinClass · 0.85

Tested by 15

test_seven_aMethod · 0.72
test_seven_bMethod · 0.72
test_seven_cMethod · 0.72
test_seven_dMethod · 0.72
test_joinsMethod · 0.72
test_full_outer_joinMethod · 0.72
goMethod · 0.72