
    ,h8                      S r SSKJr  SSKrSSKJr  SSKrSSKrSSKrSSK	r	SSK
r
SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SS	K
Jr  SS
K
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSKrSSKJ r   SSKJ!r!  SSK"J#r#  SSK"J$r$  SSK%J&r&  SSK%J'r'  SSK%J(r(  SS K%J)r)  SS!K%J*r*  SS"K%J+r+  SS#K%J,r,  SS$K%J-r-  SS%K.J/r/  SS&K.J0r0  SS'K.J1r1  SS(K.J2r2  SS)K.J3r3  SS*K.J4r4  SS+K.J5r5  SS,K.J6r6  SS-K7J8r8  SS.K7J9r9  SS/K7J:r:  S0S1KJ;r<  S0S2KJ=r=  S0S3KJ>r>  S0S4KJ?r?  S0S5KJ@r@  S0S6KJ7r7  S0S7KAJr  S0S8K@JBrB  S0S9K@JCrC  S0S:K@JDrD  S0S;K@JErE  S0S<K@JFrF  S0S=KGJHrH  S0S>KGJIrI  S0S?KJJKrK  S0S@KLJMrM  S0SAKLJNrN  S0SBKOJPrP  S0SCKOJQrQ  S0SDKOJRrR  S0SEKOJSrS  S0SFKOJTrT  S0SGKOJUrU  S0SHKOJVrV  S0SIKOJWrW  S0SJKXJYrY  S0SKKXJZrZ  S0SLKXJ[r[  \
R                  (       a  SSMK"J]r]  SSNK"J^r^  SSOK"J_r_  SSPK"J`r`  SSQK"Jara  SSRK"Jbrb  SSSK"Jcrc  SSTK%Jdrd  SSUKeJfrf  SSVKeJgrg  SSWKhJiri  SSXKjJkrk  SSYKlJmrm  SSZKnJoro  SS[KpJqrq  SS\KrJsrs  SS]KtJuru  SS^K7Jvrv  SS_K7Jwrw  S0S`KGJxrx  S0SaKGJyry  S0SbKGJzrz  S0ScKJJ{r{  S0SdKJJ|r|  S0SeKLJ}r}  S0SfKLJ~r~  S0SgKLJr  S0ShKJr  S0SiKJr  S0SjKXJr  S0SkKXJr  \" Sl\Sm9r\" Sn\Sm9r\" So\Sm9r\" Sp\Sm9r\" Sq\Sm9r\\\\   \/ \\   4   SrSs\/ Sr4   \/ Ss4   4   r\ZSt   r\\\H\   4   r\Su\\/ Su4   4   r\\ZSv   \\H\   \/ \H\   4   \/ \\H\      4   \\\\H\   4      4   r\\\\\\\4   4   4   r\\M\   \I\   \EGR&                  Sw4   r\\\\   \/ \\   4   \/ \4   \4   r\" Sx\H\   Sm9r\" SySzSm9r\\\N\   \N\   4      r\\\N\   \N\   4      r\\\N\   \N\   4      rSS{ jrSS| jr\GR:                   " S} S~\\\4   5      5       r\\ZSv   \\N\   S4   4   r " S S\5      r\>GRB                   " S S\0\6\   \>GRD                  5      5       rSS jr " S S5      r " S S5      r\" SS5      r\" SS5      r " S S\\   \&\   5      r " S S\\   \-\   \)\   5      rg)a
  Heuristics related to join conditions as used in
:func:`_orm.relationship`.

Provides the :class:`.JoinCondition` object, which encapsulates
SQL annotation and aliasing behavior focused on the `primaryjoin`
and `secondaryjoin` aspects of :func:`_orm.relationship`.

    )annotationsN)abc)Any)Callable)cast)
Collection)Dict)	FrozenSet)Generic)Iterable)Iterator)List)
NamedTuple)NoReturn)Optional)Sequence)Set)Tuple)Type)TypeVar)Union   )
attributes)strategy_options)insp_is_aliased_class)is_has_collection_adapter)_DeclarativeMapped)_is_mapped_class)class_mapper)DynamicMapped)LoaderCallableStatus)PassiveFlag)	state_str)WriteOnlyMapped)_AttributeOptions)_IntrospectsAnnotations)
MANYTOMANY)	MANYTOONE)	ONETOMANY)PropComparator)RelationshipDirection)StrategizedProperty)_orm_annotate)_orm_deannotate)CascadeOptions   )exc)Exists)log)schema)sql)util)inspect)	coercions)
expression)	operators)roles)visitors)_ColumnExpressionArgument)_HasClauseElement)_safe_annotate)ColumnClause)ColumnElement_deep_annotate)_deep_deannotate)_shallow_annotate)adapt_criterion_to_null)ClauseAdapter)join_condition)selectables_overlapvisit_binary_product)de_optionalize_union_types)Literal)resolve_name_to_real_class_name)_EntityType)_ExternalEntityType)_IdentityKeyType)_InstanceDict)_InternalEntityType)_O)_RegistryType)Mapped)_class_resolver)_ModNS)_ClassScanMapperConfig)DependencyProcessor)Mapper)Query)Session)InstanceState)
LazyLoader)AliasedClass)AliasedInsp)_CoreAdapterProto)_EquivalentColumnMap)	_InfoType)_AnnotationDict)SupportsAnnotations)BinaryExpression)BindParameter)ClauseElement)Table)
FromClause)_AnnotationScanType)RODescriptorReference_T)bound_T1_T2_PT_PT2
Mapper[_T]zAliasedClass[_T])selectjoinedselectinsubqueryraiseraise_on_sqlnoload	immediate
write_onlydynamicTFNrk   FzMapped[Any]_CEA_CEColumnElement[Any]c                d    [        [        R                  " [        R                  U 5      SS05      $ )zAnnotate a portion of a primaryjoin expression
with a 'remote' annotation.

See the section :ref:`relationship_custom_foreign` for a
description of use.

.. seealso::

    :ref:`relationship_custom_foreign`

    :func:`.foreign`

remoteT_annotate_columnsr8   expectr;   ColumnArgumentRoleexprs    T/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/orm/relationships.pyr   r      s.     11488T:J     c                d    [        [        R                  " [        R                  U 5      SS05      $ )zAnnotate a portion of a primaryjoin expression
with a 'foreign' annotation.

See the section :ref:`relationship_custom_foreign` for a
description of use.

.. seealso::

    :ref:`relationship_custom_foreign`

    :func:`.remote`

foreignTr   r   s    r   r   r      s.     11489d:K r   c                  X    \ rS rSr% SrSrS\S'   S\S'   S\S	'   SS
 jr    SS jrSr	g)_RelationshipArg   zlstores a user-defined parameter value that must be resolved and
parsed later at mapper configuration time.

)nameargumentresolvedstrr   rp   r   zOptional[_T2]r   c                    U R                   S L$ N)r   selfs    r   _is_populated_RelationshipArg._is_populated  s    }}D((r   c                    U R                   n[        U[        5      (       a   U" X R                  S:H  5      " 5       U l        g [        U5      (       a  [        U5      (       d  U" 5       U l        g X l        g )N	secondary)r   
isinstancer   r   r   callabler   )r   clsregistry_resolver
attr_values      r   _resolve_against_registry*_RelationshipArg._resolve_against_registry  s]     ]]
j#&&0II4 DM j!!*::*F*F&LDM&Mr   )r   Nreturnbool)r   &Callable[[str, bool], _class_resolver]r   None)
__name__
__module____qualname____firstlineno____doc__	__slots____annotations__r   r   __static_attributes__ r   r   r   r      s8    
 /I
IM)'$J'	'r   r   .c                  V    \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S
\S'   S
\S'   Srg)_RelationshipArgsi  zOstores user-passed parameters that are resolved at mapper configuration
time.

zP_RelationshipArg[Optional[_RelationshipSecondaryArgument], Optional[FromClause]]r   z\_RelationshipArg[Optional[_RelationshipJoinConditionArgument], Optional[ColumnElement[Any]]]primaryjoinsecondaryjoinz>_RelationshipArg[_ORMOrderByArgument, _RelationshipOrderByArg]order_byzN_RelationshipArg[Optional[_ORMColCollectionArgument], Set[ColumnElement[Any]]]foreign_keysremote_sider   N)r   r   r   r   r   r   r   r   r   r   r   r     sB    
    ML  r   r   c            $      0  ^  \ rS rSr% Sr\R                  rSr Sr	Sr
S\S'   S\S'   \" SSSSSS	9rS
rS\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S '   S!\S"'   S#\S$'     SSS
S
S
S
S
SS
S
SS%SS
S&SSSSS
S
S
S
SSS
SS
S
S
S
S
SSS
SS'."                                                                       STU 4S( jjjjrSUS) jrSVS* jr " S+ S,\R&                  \\   5      r  SW       SXS- jjr   SY         SZS. jjr          S[S/ jr  S\     S]S0 jjrS^S1 jr                  S_S2 jr\R<                  4         S`S3 jjr Sa           SbS4 jjr \!ScS5 j5       r"\#      SdS6 j5       r$SeS7 jr%\RL                  SfS8 j5       r'\RL                  SgS9 j5       r(ShU 4S: jjr)ShS; jr*ShS< jr+                    SiS= jr,\RZ                  " S>5      SaSjS? jj5       r.ShS@ jr/\!  SkSA j5       r0\!  SlSB j5       r1\RL                  \RZ                  " SC5        SmSD j5       5       r2ShSE jr3\!SnSF j5       r4\4Rj                  SoSG j5       r4SpSH jr6SqSI jr7SrSJ jr8SsSK jr9ShSL jr:\RZ                  " SM5      ShSN j5       r;\RL                  ScSO j5       r<\RL                  ScSP j5       r=      St             SuSQ jjr>SRr?U =r@$ )vRelationshipPropertyi5  zDescribes an object property that holds a single item or list
of items that correspond to a related database table.

Public constructor is the :func:`_orm.relationship` function.

.. seealso::

    :ref:`relationship_config_toplevel`

TzSequence[str]	_overlapsr_   _lazy_strategyFpassive_deletespassive_updatesenable_typechecksactive_historycascade_backrefsNzOptional[DependencyProcessor]_dependency_processorColumnElement[bool]r   Optional[ColumnElement[bool]]r   Optional[FromClause]r   JoinCondition_join_condition_RelationshipOrderByArgr   Set[ColumnElement[Any]]_user_defined_foreign_keys_calculated_foreign_keysr   local_columns_ColumnPairssynchronize_pairsOptional[_ColumnPairs]secondary_synchronize_pairslocal_remote_pairsr+   	directionr   
_init_argszsave-update, mergeru   )"uselistcollection_classr   r   back_populatesr   backrefoverlapspost_updatecascadeviewonlyattribute_optionslazyr   r   r   r   r   r   
join_depthcomparator_factorysingle_parent	innerjoindistinct_target_keyload_on_pendingquery_classinfo	omit_joinsync_backrefdocbake_queriesr   _local_remote_pairs_legacy_inactive_history_stylec       "          > [         T%U ]  US9  X0l        Xl        [	        [        SUS 5      [        SUS 5      [        SUS 5      [        SUS 5      [        SUS 5      [        SUS 5      5      U l        Xl        Xl        U(       a  U R                  UUUUU"S9  U(       a  U(       a  [        R                  " S	5      eUU l        Xl        UU l        X@l        UU l        U"(       a  [        R                  " S
5      eUU l        UU l        UU l        UU l        UU l        U U l        UU l        U$U l        UU l        U(       a  [4        R6                  " S5        UU l        U#U l        UU l        U=(       d    [>        R@                  U l!        [4        RD                  " U 5        Ub  U RF                  RI                  U5        SU R                  44U l%        [M        5       U l'        U
(       a&  [M        [P        RR                  " SU
5      5      U l*        OSU l*        Xl+        Xpl,        U RX                  (       a%  U	(       a  [        R                  " S5      eS U l-        g Xl-        g )N)r   r   r   r   r   r   r   r   z-sync_backref and viewonly cannot both be TruezSThe 'cascade_backrefs' parameter passed to relationship() may only be set to False.zsetting omit_join to True is not supported; selectin loading of this relationship may not work correctly if this flag is set explicitly.  omit_join optimization is automatically detected for conditions under which it is supported.r   z\s*,\s*r   zCbackref and back_populates keyword arguments are mutually exclusive).super__init__r   r   r   r   r   r   r    _warn_for_persistence_only_flagssa_excArgumentErrorr   r   r   r   r   r   r   r   r   r   r   r   r   r   r6   warnr   r   r   r   
Comparatorr   set_creation_orderr   updatestrategy_keyset_reverse_propertyresplitr   r   r   r   )&r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	__class__s&                                        r   r   RelationshipProperty.__init__n  s5   X 	+<= +[)T:]K>_mTBZ48^\4@]K>
 ' 11 / /"3-!1 2  &&?  )	* 0.&&; 
  /!2&"#6 ,.L+$II #"5.A"6"A"A 	 	%IIT"$dii02AD *h!?@DNDN ,**-   DL"Lr   c                    UR                  5        H4  u  p#X0R                  U   :w  d  M  [        R                  " SU< S35        M6     g )NzSetting z on relationship() while also setting viewonly=True does not make sense, as a viewonly=True relationship does not perform persistence operations. This configuration may raise an error in a future release.)items_persistence_onlyr6   r   )r   kwkvs       r   r   5RelationshipProperty._warn_for_persistence_only_flags  s=    HHJDA**1-- 		
 /0	2 r   c                    [         R                  " UR                  U R                  U R	                  X5      UU R
                  S9  g )N)
comparatorparententityr   )r   register_descriptorclass_keyr   r   r   mappers     r   instrument_class%RelationshipProperty.instrument_class
  s6    &&MMHH..t<	
r   c                  h   \ rS rSr% SrSrS\S'   S\S'      S         S S	 jjr    S!S
 jrS\S'    S\S'    S"S jr	S#S jr
S$S jrS%S jrS&S jr    S'S jrS(S jrSrS)S jr S*     S+S jjr S*     S,S jjr S*     S,S jjr      S-S jr    S)S jrS)S jrS.S jrSrg)/RelationshipProperty.Comparatori  a  Produce boolean, comparison, and other operators for
:class:`.RelationshipProperty` attributes.

See the documentation for :class:`.PropComparator` for a brief
overview of ORM level operator definition.

.. seealso::

    :class:`.PropComparator`

    :class:`.ColumnProperty.Comparator`

    :class:`.ColumnOperators`

    :ref:`types_operators`

    :attr:`.TypeEngine.comparator_factory`

)entityr  property_of_type_extra_criteriaz0RODescriptorReference[RelationshipProperty[_PT]]propOptional[_EntityType[_PT]]r  Nc                ^    Xl         X l        X0l        U(       a  X@l        OSU l        XPl        g)ziConstruction of :class:`.RelationshipProperty.Comparator`
is internal to the ORM's attribute mechanics.

N)r  _parententity_adapt_to_entityr  r  )r   r  parentmapperadapt_to_entityof_typeextra_criterias         r   r   (RelationshipProperty.Comparator.__init__3  s*     I!-$3! ' $#1 r   c                b    U R                  U R                  U R                  UU R                  S9$ )N)r  r  )r   r  r  r  )r   r  s     r   r  /RelationshipProperty.Comparator.adapt_to_entityH  s4     >>		"" /	 "  r   _InternalEntityType[_PT]r  Mapper[_PT]r  c                z    U R                   (       a  [        U R                   5      $ U R                  R                  $ r   )r  r7   r  r  r   s    r   _memoized_attr_entity5RelationshipProperty.Comparator._memoized_attr_entityg  s(    }}t}}--yy'''r   c                .    U R                   R                  $ r   r  r  r   s    r   _memoized_attr_mapper5RelationshipProperty.Comparator._memoized_attr_mapperm  s    ;;%%%r   c                    U R                   (       a  U R                   R                  $ U R                  R                  R                  $ r   )r  
selectabler  parent_with_polymorphic_selectabler   s    r   _source_selectable2RelationshipProperty.Comparator._source_selectablep  s3    $$,,777}}++HHHr   c                    U R                  5       nU R                  (       a  [        U R                  5      nOS nU R                  R	                  USUSU R
                  S9u  nnnnnnUb  X4-  $ U$ )NT)source_selectablesource_polymorphicof_type_entityalias_secondaryr  )r-  r  r7   r  _create_joinsr  )	r   
adapt_fromr2  pjsjsourcedestr   target_adapters	            r   __clause_element__2RelationshipProperty.Comparator.__clause_element__v  s    002J}}!(!7!% 		''",#'- $#33 (  ~w	r   c                    [         R                  U R                  U R                  U R                  UU R
                  S9$ )zpRedefine this object in terms of a polymorphic subclass.

See :meth:`.PropComparator.of_type` for an example.


r  r  r  )r   r   r  r  r  r  )r   r  s     r   r  'RelationshipProperty.Comparator.of_type  sA     (22		"" $ 5 5#33 3  r   c                    [        S [        R                  " U5       5       5      n[        R	                  U R
                  U R                  U R                  U R                  U R                  U-   S9$ )z\Add AND criteria.

See :meth:`.PropComparator.and_` for an example.

.. versionadded:: 1.4

c              3  l   #    U  H*  n[         R                  " [        R                  U5      v   M,     g 7fr   )r8   r   r;   WhereHavingRole).0clauses     r   	<genexpr>7RelationshipProperty.Comparator.and_.<locals>.<genexpr>  s-      AF   !6!6??As   24r>  )
tupler6   coerce_generator_argr   r   r  r  r  r  r  )r   criteriaexprss      r   and_$RelationshipProperty.Comparator.and_  sn      "77A E
 (22		"" $ 5 5#33e; 3  r   c                    [        S5      e)zmProduce an IN clause - this is not implemented
for :func:`_orm.relationship`-based attributes at this time.

zvin_() not yet supported for relationships.  For a simple many-to-one, use in_() against the set of foreign key values.)NotImplementedErrorr   others     r   in_#RelationshipProperty.Comparator.in_  s    
 &1 r   c                   Ub  [        U[        R                  5      (       ab  U R                  R                  [
        [        4;   a  U R                  5       ) $ [        U R                  R                  SU R                  S95      $ U R                  R                  (       a  [        R                  " S5      e[        U R                  R                  XR                  S95      $ )a  Implement the ``==`` operator.

In a many-to-one context, such as:

.. sourcecode:: text

  MyClass.some_prop == <some object>

this will typically produce a
clause such as:

.. sourcecode:: text

  mytable.related_id == <some id>

Where ``<some id>`` is the primary key of the given
object.

The ``==`` operator provides partial functionality for non-
many-to-one comparisons:

* Comparisons against collections are not supported.
  Use :meth:`~.Relationship.Comparator.contains`.
* Compared to a scalar one-to-many, will produce a
  clause that compares the target columns in the parent to
  the given target.
* Compared to a scalar many-to-many, an alias
  of the association table will be rendered as
  well, forming a natural join that is part of the
  main body of the query. This will not work for
  queries that go beyond simple AND conjunctions of
  comparisons, such as those which use OR. Use
  explicit joins, outerjoins, or
  :meth:`~.Relationship.Comparator.has` for
  more comprehensive non-many-to-one scalar
  membership tests.
* Comparisons against ``None`` given in a one-to-many
  or many-to-many context produce a NOT EXISTS clause.

Nadapt_source]Can't compare a collection to an object or collection; use contains() to test for membership.)r   r9   Nullr  r   r)   r'   _criterion_existsr-   _optimized_compareadapterr   r   InvalidRequestErrorrO  s     r   __eq__&RelationshipProperty.Comparator.__eq__  s    R }
5*// B B==**y*.EE 22444(88 t|| 9  
 &&00= 
 %MM44LL 5  r   c                   Ub%  [         R                  " [        R                  U5      OS n[	        U SS 5      (       a  [        U R                  5      nUc   eUR                  UR                  UR                  pvnU R                  R                  (       a  U(       d  UR                  5       nUR                  nUb
  Ub  X-  nOUnOSnS nU R                  (       a  U R                  5       n	OS n	U R                  R!                  UU	S9u  n
nnnnnU H?  n[	        U R                  R                  R"                  U5      UU   :H  nUc  UnM:  UU-  nMA     Ub  [%        U
5      U-  nO[%        XR                  R&                  S9nUb  U(       a  U(       d  UR)                  U5      nUb  UR+                  SS05      nU[,        R.                  R1                  U5      -  nUbE  [,        R2                  " S5      R5                  U5      R7                  X5      R9                  X5      nU$ [,        R2                  " S5      R5                  U5      R7                  U5      R9                  U5      nU$ )Nr  F)dest_selectabler0  )excludeno_replacement_traverseTr   )r8   r   r;   rB  getattrr7   r  r  r*  is_aliased_classr  _is_self_referential_anonymous_fromclause_single_table_criterionrZ  r-  r4  r  r-   r   traverse	_annotater5   True__ifnoneexistswhereselect_fromcorrelate_except)r   	criterionkwargswhere_criteriar   target_mapperto_selectablerc  single_critr0  r6  r7  r8  r9  r   r:  r  critjexs                       r   rX  1RelationshipProperty.Comparator._criterion_exists  sW    (   !6!6	B  tZ..;BMM< '''KKOO)) /?
 ==55>N$1$G$G$IM+CC*%1)4)E)4#(  $||$($;$;$=!$(! ++ -"3 ,  t}}33::A>&)K!)%)N%3d%:N  ~!"%*!"mm.G.GH *"( "0!8!8!H )!/!9!9.5" syy((88D$JJqMU4[ [1%%d6	  I JJqMU4[ [&%%d+	  Ir   c                    U R                   R                  (       d  [        R                  " S5      eU R                  " U40 UD6$ )a*  Produce an expression that tests a collection against
particular criterion, using EXISTS.

An expression like::

    session.query(MyClass).filter(
        MyClass.somereference.any(SomeRelated.x == 2)
    )

Will produce a query like:

.. sourcecode:: sql

    SELECT * FROM my_table WHERE
    EXISTS (SELECT 1 FROM related WHERE related.my_id=my_table.id
    AND related.x=2)

Because :meth:`~.Relationship.Comparator.any` uses
a correlated subquery, its performance is not nearly as
good when compared against large target tables as that of
using a join.

:meth:`~.Relationship.Comparator.any` is particularly
useful for testing for empty collections::

    session.query(MyClass).filter(~MyClass.somereference.any())

will produce:

.. sourcecode:: sql

    SELECT * FROM my_table WHERE
    NOT (EXISTS (SELECT 1 FROM related WHERE
    related.my_id=my_table.id))

:meth:`~.Relationship.Comparator.any` is only
valid for collections, i.e. a :func:`_orm.relationship`
that has ``uselist=True``.  For scalar references,
use :meth:`~.Relationship.Comparator.has`.

z9'any()' not implemented for scalar attributes. Use has().r  r   r   r[  rX  r   ro  rp  s      r   any#RelationshipProperty.Comparator.anyi  sB    \ ==((00- 
 )))>v>>r   c                    U R                   R                  (       a  [        R                  " S5      eU R                  " U40 UD6$ )a  Produce an expression that tests a scalar reference against
particular criterion, using EXISTS.

An expression like::

    session.query(MyClass).filter(
        MyClass.somereference.has(SomeRelated.x == 2)
    )

Will produce a query like:

.. sourcecode:: sql

    SELECT * FROM my_table WHERE
    EXISTS (SELECT 1 FROM related WHERE
    related.id==my_table.related_id AND related.x=2)

Because :meth:`~.Relationship.Comparator.has` uses
a correlated subquery, its performance is not nearly as
good when compared against large target tables as that of
using a join.

:meth:`~.Relationship.Comparator.has` is only
valid for scalar references, i.e. a :func:`_orm.relationship`
that has ``uselist=False``.  For collection references,
use :meth:`~.Relationship.Comparator.any`.

z3'has()' not implemented for collections. Use any().rz  r{  s      r   has#RelationshipProperty.Comparator.has  s@    B }}$$00I  )))>v>>r   c                   U R                   R                  (       d  [        R                  " S5      eU R                   R	                  XR
                  S9nU R                   R                  b  U R                  U5      Ul        U$ )a  Return a simple expression that tests a collection for
containment of a particular item.

:meth:`~.Relationship.Comparator.contains` is
only valid for a collection, i.e. a
:func:`_orm.relationship` that implements
one-to-many or many-to-many with ``uselist=True``.

When used in a simple one-to-many context, an
expression like::

    MyClass.contains(other)

Produces a clause like:

.. sourcecode:: sql

    mytable.id == <some id>

Where ``<some id>`` is the value of the foreign key
attribute on ``other`` which refers to the primary
key of its parent object. From this it follows that
:meth:`~.Relationship.Comparator.contains` is
very useful when used with simple one-to-many
operations.

For many-to-many operations, the behavior of
:meth:`~.Relationship.Comparator.contains`
has more caveats. The association table will be
rendered in the statement, producing an "implicit"
join, that is, includes multiple tables in the FROM
clause which are equated in the WHERE clause::

    query(MyClass).filter(MyClass.contains(other))

Produces a query like:

.. sourcecode:: sql

    SELECT * FROM my_table, my_association_table AS
    my_association_table_1 WHERE
    my_table.id = my_association_table_1.parent_id
    AND my_association_table_1.child_id = <some id>

Where ``<some id>`` would be the primary key of
``other``. From the above, it is clear that
:meth:`~.Relationship.Comparator.contains`
will **not** work with many-to-many collections when
used in queries that move beyond simple AND
conjunctions, such as multiple
:meth:`~.Relationship.Comparator.contains`
expressions joined by OR. In such cases subqueries or
explicit "outer joins" will need to be used instead.
See :meth:`~.Relationship.Comparator.any` for
a less-performant alternative using EXISTS, or refer
to :meth:`_query.Query.outerjoin`
as well as :ref:`orm_queryguide_joins`
for more details on constructing outer joins.

kwargs may be ignored by this operator but are required for API
conformance.
z9'contains' not implemented for scalar attributes.  Use ==rT  )	r  r   r   r[  rY  rZ  r   '_Comparator__negated_contains_or_equalsnegation_clause)r   rP  rp  rD  s       r   contains(RelationshipProperty.Comparator.contains  s{    B 99$$00* 
 YY11LL 2 F yy&&2)-)J)J*& Mr   c                  ^  T R                   R                  [        :X  a  [        R                  " U5      n        SU 4S jjnSU 4S jjnT R
                  R                  (       ap  [        R                  " T R
                  R                   VVs/ s H;  u  pV[        R                  " U" U5      U" U" U5      X&5      :g  U" U5      S :H  5      PM=     snn6 $ [        R                  " [        T R
                  R                  R                  T R
                  R                  R                  U5      5       VVs/ s H	  u  pVXV:H  PM     snn6 nT R                  U5      ) $ s  snnf s  snnf )Nc                   > UR                   n[        R                  " U R                  U R                  STR
                  R                  TR
                  R                  XU5      S9$ )NT)type_unique	callable_)dictr5   	bindparamr	  typer  _get_attr_w_warn_on_noner  )	local_colstate
remote_coldict_r   s       r   state_bindparamURelationshipProperty.Comparator.__negated_contains_or_equals.<locals>.state_bindparam  sS    
 "JJE==!'nn#"&))"D"D II,,eJ#	 r   c                L   > TR                   (       a  TR                  U 5      $ U $ r   )rZ  )colr   s    r   adaptKRelationshipProperty.Comparator.__negated_contains_or_equals.<locals>.adapt-  s    ||#||C00"
r   )r  r   r  InstanceState[Any]r  r   r   BindParameter[Any])r  r   r   r   )r  r   r(   r   instance_stater  _use_getr5   rK  r   or_zipr  primary_keyprimary_key_from_instancerX  )r   rP  r  r  r  xyro  s   `       r   __negated_contains_or_equals<RelationshipProperty.Comparator.__negated_contains_or_equals  sY    yy""i/"11%81- !3 (	# ==))88 +/--*J*J +K  GG %a#258U#F!G %aD 0
 +K	 	  #&,,88,,FFuM## F#I **9555)s   AE 
9E&
c                   Ub  [        U[        R                  5      (       a\  U R                  R                  [
        :X  a.  [        U R                  R                  SU R                  S9) 5      $ U R                  5       $ U R                  R                  (       a  [        R                  " S5      e[        U R                  U5      5      $ )a  Implement the ``!=`` operator.

In a many-to-one context, such as:

.. sourcecode:: text

  MyClass.some_prop != <some object>

This will typically produce a clause such as:

.. sourcecode:: sql

  mytable.related_id != <some id>

Where ``<some id>`` is the primary key of the
given object.

The ``!=`` operator provides partial functionality for non-
many-to-one comparisons:

* Comparisons against collections are not supported.
  Use
  :meth:`~.Relationship.Comparator.contains`
  in conjunction with :func:`_expression.not_`.
* Compared to a scalar one-to-many, will produce a
  clause that compares the target columns in the parent to
  the given target.
* Compared to a scalar many-to-many, an alias
  of the association table will be rendered as
  well, forming a natural join that is part of the
  main body of the query. This will not work for
  queries that go beyond simple AND conjunctions of
  comparisons, such as those which use OR. Use
  explicit joins, outerjoins, or
  :meth:`~.Relationship.Comparator.has` in
  conjunction with :func:`_expression.not_` for
  more comprehensive non-many-to-one scalar
  membership tests.
* Comparisons against ``None`` given in a one-to-many
  or many-to-many context produce an EXISTS clause.

NrT  rV  )r   r9   rW  r  r   r(   r-   rY  rZ  rX  r   r   r[  r  rO  s     r   __ne__&RelationshipProperty.Comparator.__ne__K  s    V }
5*// B B==**i7(99 t|| :     1133&&009  %T%F%Fu%MNNr   c                b    U R                   R                  R                  5         U R                   $ r   )r  r+  _check_configurer   s    r   _memoized_attr_property7RelationshipProperty.Comparator._memoized_attr_property  s"    II--/99r   )r  r  r  r  r  )NNr   )
r  RelationshipProperty[_PT]r  z_InternalEntityType[Any]r  zOptional[AliasedInsp[Any]]r  r  r  Tuple[ColumnElement[bool], ...])r  zAliasedInsp[Any]r   z$RelationshipProperty.Comparator[Any])r   r   )r   r!  )r   rk   r   r   )r  z_EntityType[Any]r   zPropComparator[_PT])rI  z_ColumnExpressionArgument[bool]r   zPropComparator[Any])rP  r   r   r   )rP  r   r   r   r   )ro  )Optional[_ColumnExpressionArgument[bool]]rp  r   r   r2   )ro  r  rp  r   r   r   )rP  z_ColumnExpressionArgument[Any]rp  r   r   r   )r   r  )r   r   r   r   r   r   r   r   r  r#  r'  r-  r;  r  rK  rQ  __hash__r\  rX  r|  r  r  r  r  r  r   r   r   r   r   r    s   	(
	 ?>,, ;?26>@	2+	2 3	2 8		2
 0	2 <	2*	#3	1	 )(		 		(	&	I	4		<	 	.
	 <	@ DHd	@d	 d	 	d	P DH4	?@4	? 4	? !	4	?p DH%	?@%	? %	? !	%	?NP	7P	CFP	 P	d1	61	6 1	6f<	O|	r   r   c                    Uc   eS nUb6  [        U5      nUc   e[        U5      (       a  UR                  R                  nU R	                  USUUS9$ )NT)value_is_parentrU  r3  )r7   r   _adapteradapt_clauserY  )r   instancer3  from_entityrU  insps         r   _with_parent!RelationshipProperty._with_parent  so     ###48"7>{7KD###$T**#}}99&& %+	 ' 
 	
r   c                8  ^ ^^^	^
 Tb:   [        T5      mTb  [        TSS5      (       d  [        R                  " ST -  5      eU(       + nTc  T R                  XSS9$ U(       d.  T R                  R                  T R                  R                  snmO-T R                  R                  T R                  R                  snmU(       a  T R                  m
OT R                  m
[        R                  " TR                  5       5      m	SUU	U
U U4S jjnT R                   b9  U(       a2  [#        T R                   R%                  5       5      R'                  U5      n[(        R*                  " U0 SU05      nU(       a  U" U5      nU$ ! [        R                   a    S m GNf = f)Nis_instanceFzMapped instance expected for relationship comparison to object.   Classes, queries and other SQL elements are not accepted in this context; for comparison with a subquery, use %s.has(**criteria).rT  r  c                t   > U R                   T;   a'  TR                  TTTTU R                      5      U l        g g r   )_identifying_keyr  r   )r  bind_to_colr  r  r   r  s    r   visit_bindparam@RelationshipProperty._optimized_compare.<locals>.visit_bindparam  s@    ))[8%)%B%B	 : :;	&	" 9r   )r  r  r   r   )r7   r   NoInspectionAvailablerb  r   _lazy_none_clauser   
_lazywhere_bind_to_col_rev_lazywhere_rev_bind_to_colr  r+  r   instance_dictobjr   rG   re  rg  r<   cloned_traverse)r   r  r  rU  r3  reverse_directionro  r  r  r  r  s   ``      @@@r   rY  'RelationshipProperty._optimized_compare  s     }GE=%$H$H**. 15	5  !0/=))! *   !##..##00 #I{ ##22##44 #I{
 [[F[[F((5	 	 >>%/%446hy!  ,,rK9
	 $Y/Iq // s   E? ?FFc                   ^^^^^^ TR                  T5      mTR                  TR                  5        TR                  mSUUUUUU4S jjnU$ )a  Create the callable that is used in a many-to-one expression.

E.g.::

    u1 = s.query(User).get(5)

    expr = Address.user == u1

Above, the SQL should be "address.user_id = 5". The callable
returned by this method produces the value "5" based on the identity
of ``u1``.

c                 B  > Tc   eTTR                      =pU [        R                  LnTR                  T	TTT	R                  (       a  [
        R                  O [
        R                  [
        R                  -  S9nU[        R                  L a0  U(       d(  [        R                  " ST< S[        T	5      < S35      eOEU[        R                  L a0  U(       d(  [        R                  " ST< S[        T	5      < S35      eOUnUc  [        R                  " ST-  5        U$ )NpassivezCan't resolve value for column z on object z'; no value has been set for this columnz2; the object is detached and the value was expiredzGot None for value of column %s; this is unsupported for a relationship comparison and will not currently produce an IS comparison (but may in a future release))r	  r!   NO_VALUE_get_state_attr_by_column
persistentr"   PASSIVE_OFFPASSIVE_NO_FETCHINIT_OK	NEVER_SETr   r[  r#   PASSIVE_NO_RESULTr6   r   )

last_known	to_returnexisting_is_availablecurrent_valuecolumnr  	lkv_fixedr  r  r  s
       r   _go:RelationshipProperty._get_attr_w_warn_on_none.<locals>._go  s(   (((%.txx%88J"6"?"?? " #<< ''  ++$558K8KK = 	M  4 > >>, 44 "9U#35  - "6"H"HH, 44 &,Yu-=?  - *	 		4 7== r   )r   r   )get_property_by_column_track_last_known_valuer	  _last_known_values)r   r  r  r  r  r  r  r  s    ```` @@r   r  -RelationshipProperty._get_attr_w_warn_on_none  sG    b ,,V4
 	%%dhh/,,	-	 -	^ 
r   c                    U(       d,  U R                   R                  U R                   R                  pCO+U R                   R                  U R                   R                  pC[        X45      nU(       a  U" U5      nU$ r   )r   r  r  r  r  rF   )r   r  rU  ro  r  s        r   r  &RelationshipProperty._lazy_none_clauseP  sn    
 !##..##00 # ##22##44 #
 ,IC	$Y/Ir   c                t    [        U R                  R                  R                  5      S-   U R                  -   $ )N.)r   r+  r  r   r	  r   s    r   __str__RelationshipProperty.__str__f  s+    4;;%%../#5@@r   c	           	        U(       a  U R                    H  n	X)4U;   d  M    g    SU R                  ;  a  g U R                  U;  a  g U R                  (       Ga  UR	                  U R                  5      n
[        U
5      (       d   eU
R                  X#5      nU
R                  (       a  UR                  (       a   e U(       a7  UR	                  U R                  5      R                  XE[        R                  S9  / nU H^  n[        R                  " U5      n[        R                  " U5      nSX~U 4'   UR                  UUUUUS9nUc  MM  UR!                  U5        M`     U(       d<  [        R"                  " XEU R                  5      nU H  nUR%                  U5        M     g UR	                  U R                  5      n[        U5      (       d   eUR'                  UUUS[        R                  S9  g X0R                     nUbF  [        R                  " U5      n[        R                  " U5      nSX~U 4'   UR                  UUUUUS9nOS nU(       d  UXPR                  '   g UR	                  U R                  5      R'                  XEUS 5        g )NmergeTr  )load
_recursive_resolve_conflict_mapF)_adaptr  )r   _cascader	  r   get_implr   get_collection
collectionemptygetr"   PASSIVE_MERGEr   r  r  _mergeappendinit_state_collectionappend_without_eventr   )r   sessionsource_statesource_dict
dest_state	dest_dictr  r  r  rimplinstances_iterable	dest_listcurrentcurrent_statecurrent_dictr  collc	dest_impls                       r   r  RelationshipProperty.mergei  sg    ++ $
2 , $--'88;&<<<((2D,T2222!%!4!4\!O
 48??)//LL ##DHH-11;3L3L 2  I- * 9 9' B)77@48
401nn! )*? %  ?$$S) . !77488 #A--a0 # '//9	0;;;; '55   "((+G" * 9 9' B)77@48
401nn! )*? %  &)	((###DHH-113r   c                N   UR                   U   R                  nUR                  XUS9nU[        R                  L d  Uc  / $ [        U5      (       a7  UR                  XXdS9 Vs/ s H  n[        R                  " U5      U4PM     sn$ [        R                  " U5      U4/$ s  snf )z|Return a list of tuples (state, obj) for the given
key.

returns an empty list if the value is None/empty/PASSIVE_NO_RESULT
r  )	managerr  r  r!   r  r   r  r   r  )r   r  r  r	  r  r  r  os           r   _value_as_iterable'RelationshipProperty._value_as_iterable  s     }}S!&&HHU7H3$666!)I&t,, ,,U1,NNA **1-q1N 
  ..q11566s   $"B"c           
   #    #    US:w  d  U R                   (       a  [        R                  nO![        R                  [        R                  -  nUS:X  a3  UR
                  U R                     R                  R                  X#5      nOU R                  X#U R                  US9nUS:H  =(       a    SU R                  ;  nU H  u  pX;   a  M  U
c  M  U	c   e[        R                  " U
5      nU(       a  U" U	5      (       a  MB  U(       a  U	R                  (       d  M\  U	R
                  R                  nUR                  U R                  R                  R                  5      (       d@  [!        SU R                  < SU R"                  R$                  < SU
R&                  < S	35      eUR)                  U	5        XX4v   M     g 7f)
Ndeletezsave-updater  zrefresh-expiredelete-orphanzAttribute 'z' on class 'z"' doesn't handle objects of type '')r   r"   PASSIVE_NO_INITIALIZEr  NO_RAISEr  r	  r  get_all_pendingr  r  r   r  r  isaclass_managerAssertionErrorr+  r  r   add)r   r  r  r  visited_stateshalt_onr  tuplesskip_pendingr  r  r  instance_mappers                r   cascade_iterator%RelationshipProperty.cascade_iterator  sy     H 4 4!77G!--0D0DDGM!]]488,11AA%OF,,dhh - F
 %%N/*N 	 "(N/y
 !---&44Q7M7>22N$6$6,44;;O"&&t{{'@'@'G'GHH$ xx!3!3Q[[B  ~.nCCA "(s   F=F?c                B    U R                   (       a  gU R                  SL$ )NF)r   r   r   s    r   _effective_sync_backref,RelationshipProperty._effective_sync_backref   s    ==$$E11r   c                    U R                   (       a0  UR                  (       a  [        R                  " SU< SU < S35      eU R                   (       a*  UR                   (       d  UR                  SLa  SUl        g g g g )NRelationship z( cannot specify sync_backref=True since z includes viewonly=True.F)r   r   r   r[  )rel_arel_bs     r   _check_sync_backref(RelationshipProperty._check_sync_backref'  se     >>e00,,-2E; 
 NNNN""%/!&E 0 # r   c           
     
   U R                   R                  USS9n[        U[        5      (       d  [        R
                  " SU < SU< S35      eU R                  X5        U R                  X 5        U R                  R                  U5        UR                  R                  U 5        UR                  5         UR                   R                  U R                  5      (       d0  [        R                  " SU< SU < SU< S	U R                  < 35      eUR                  (       ab  U R                  [        [         4;   aG  U R                  UR                  :X  a,  [        R                  " U< S
U < SU R                  < S35      eg g g )NF)_configure_mappersz back_populates on relationship 'z' refers to attribute 'z{' that is not a relationship.  The back_populates parameter should refer to the name of a relationship on the target class.zreverse_property z on relationship z references relationship z", which does not reference mapper z and back-reference z  are both of the same direction z<.  Did you mean to set remote_side on the many-to-one side ?)r  get_propertyr   r   r   r[  r)  r   r  _setup_entitycommon_parentr+  r   _configure_startedr   r)   r(   )r   r	  rP  s      r   _add_reverse_property*RelationshipProperty._add_reverse_property7  s<   (((G%!566,, !%)  	  - 	  -""5)##D)||))$++66&& eT[[2  $$9i"88%//1&& $0  2 9 %r   c                N    U R                   R                  5         U R                  $ )zReturn the target mapped entity, which is an inspect() of the
class or aliased class that is referenced by this
:class:`.RelationshipProperty`.

)r+  r  r  r   s    r   r  RelationshipProperty.entityc  s     	$$&{{r   c                .    U R                   R                  $ )zSReturn the targeted :class:`_orm.Mapper` for this
:class:`.RelationshipProperty`.

r&  r   s    r   r  RelationshipProperty.mapperm  s     {{!!!r   c                  > U R                  5         U R                  5         U R                  5         U R                  5         U R	                  5         U R                  U R                  5        U R                  5         U R                  5         U R                  R                  5         [        TU ]1  5         [        SU R                  S5      5      U l        g )Nr_   ))r   ru   )_check_conflicts_process_dependent_argumentsr.  _setup_registry_dependencies_setup_join_conditions_check_cascade_settingsr  
_post_init_generate_backrefr   "_warn_for_conflicting_sync_targetsr   do_initr   _get_strategyr   )r   r   s    r   r@  RelationshipProperty.do_initu  s    ))+))+##%$$T]]3 ??A"$,,-BC
r   c                    U R                   R                  R                  R                  U R                  R                  R                  5        g r   )r+  r  registry_set_depends_onr  r   s    r   r:  1RelationshipProperty._setup_registry_dependencies  s3    ##33KK''	
r   c           	        U R                   nS H,  n[        X5      nUR                  U R                  S   5        M.     S HP  n[        X5      nUR                  nUc  M  [        [        R                  " [        R                  XBS95      Ul        MR     UR                  R                  nUb/  [        U5      (       a  [        R                  " SU< SU < S35      eUR                  R                  S	LaW  UR                  R                  b@  [        S
 [         R"                  " UR                  R                  5       5       5      U l        OS	U l        [         R$                  " S [         R&                  " UR(                  R                  5       5       5      U l        [         R$                  " S [         R&                  " UR,                  R                  5       5       5      U l        g)zrConvert incoming configuration arguments to their
proper form.

Callables are resolved, ORM annotations removed.

)r   r   r   r   r   r   r   )r   r   Nargnamezsecondary argument z passed to to relationship() z must be a Table object or other FROM clause; can't send a mapped class directly as rows in 'secondary' are persisted independently of a class that is mapped to that same table.Fc              3  j   #    U  H)  n[         R                  " [        R                  US S9v   M+     g7f)r   rH  Nr8   r   r;   r   rC  r  s     r   rE  DRelationshipProperty._process_dependent_arguments.<locals>.<genexpr>  s5      " CA   ,,a C   13c              3  j   #    U  H)  n[         R                  " [        R                  US S9v   M+     g7f)r   rH  NrK  rL  s     r   rE  rM    s5      :
 I ((!^ IrN  c              3  j   #    U  H)  n[         R                  " [        R                  US S9v   M+     g7f)r   rH  NrK  rL  s     r   rE  rM    s5      +
 H ((!] HrN  )r   rb  r   _clsregistry_resolversr   r.   r8   r   r;   r   r   r   r   r   r   rG  r6   to_list
column_setto_column_setr   r   r   )r   	init_argsattrrel_argvalr   s         r   r9  1RelationshipProperty._process_dependent_arguments  s    OO	
D i.G--d.I.I!.LM
 3Di.G""C#2$$00#$ 	 3 ''00	 %5i%@%@&&
 *3D	:  ''u4""++7! " i&8&8&A&AB	" DM "DM*.// :
 ''	(>(>(G(GH	:
 +
'  ?? +
 ''	(=(=(F(FG	+
 
r   c
                   Uc   U R                   c  U R                  XS5        Og Un
Uc   eUbf  [        U[        5      n[        U[        5      nU(       a  SU l        SU R
                  44U l        O&U(       a  SU l        SU R
                  44U l        OS=p[        U
5      n
[        U
S5      (       GaH  U
R                  n[        U[        5      (       ah  [        U[        R                  5      (       aI  U R                  c;  [        R                   " U5      (       a  ["        R$                  " SU S35      eXl        OU(       d  U(       d  SU l        U
R(                  (       a  [        U[        5      (       a/  [        U[*        R,                  5      (       a  U
R(                  S   nOU
R(                  S	   n[        US
5      (       a  UR.                  n[1        X5      n
OEUn
OB["        R$                  " SU
 S35      e[        U
S
5      (       a  U
R.                  n
[1        X5      n
U R                  c  U(       d  U(       d  SU l        U R                   c  [3        SU
5      U l         g g )Nr}   r   r~   F
__origin__zCollection annotation type z cannot be instantiated; please provide an explicit 'collection_class' parameter (e.g. list, set, etc.) to the relationship() function to accompany this annotationr   __forward_arg__zGeneric alias z requires an argumentz_RelationshipArgumentType[_T])r   _raise_for_required
issubclassr$   r    r   r   rL   hasattrr[  r   r  r   r   r   _py_inspect
isabstractr   r   r   __args__typingMappingr]  rN   r   )r   	decl_scanrD  clsoriginating_moduler	  mapped_container
annotationextracted_mapped_annotationis_dataclass_fieldr   is_write_only
is_dynamic
arg_origintype_argstr_arguments                   r   declarative_scan%RelationshipProperty.declarative_scan  s5    '.}}$((2.!---'&'7IM#$4mDJ(	&,dii%8$:!%	&,dii%8$:!)..M-h78\**!,,J*d++
CNN1 1 ((0"--j99$229* F) )  -7)":$  j$//J5 5  (004H'003H8%677#+#;#;L>$ H  (H**$XJ.CD  X011//H6H
 !!)! DL ==  !@(KDM !r   zsqlalchemy.orm.mapperc                   SU R                   ;   a  g [        R                  R                  nU(       a  UnOU R                  n[        U[        5      (       a!  [        SU R                  U5      " 5       5      nO;[        U5      (       a)  [        U[        UR                  45      (       d  U" 5       nOUn[        U[        5      (       a  [        USS9nOO [        U5      n[!        US5      (       d2  [        R"                  " SU R$                  < S[        U5      < S35      eXPl        U R&                  R(                  U l        g ! [        R                   a    S n N}f = f)	Nr  z_ExternalEntityType[Any]F	configurer  relationship 'z2' expects a class or a mapper argument (received: ))__dict__r6   	preloaded
orm_mapperr   r   r   r   _clsregistry_resolve_namer   r  r[   r   r7   r   r  r`  r   r	  r  persist_selectabletarget)r   _RelationshipProperty__argument	mapperlibr   resolved_argumentr  s         r   r.  "RelationshipProperty._setup_entity7  s3   t}}$NN--	!H}}H h$$ !%*..x8:! h
tY--.)
 )
 !)
 ( '..!"3uEF !23 68,,** xx&7!8:  kk44 // s   E EEc                   [        S0 SU R                  R                  _SU R                  R                  _SU R                  R                  _SU R                  R                  _SU R
                  R                  R                  _SU R
                  R                  R                  _SU R
                  R                  R                  _SU R                  R                  _S	U R                  R                  _S
U R                  _SU R                  _SU R                  _SU R                  _SU _SU R                   (       + _SU R"                  _6=U l        nUR                  U l        UR                  U l	        UR                  U l        UR&                  U l        UR                  U l        UR(                  U l        UR*                  U l        UR,                  U l        UR.                  U l        UR2                  U l        g )Nparent_persist_selectablechild_persist_selectableparent_local_selectablechild_local_selectabler   r   r   parent_equivalentschild_equivalentsconsider_as_foreign_keysr   r   self_referentialr  support_synccan_be_synced_fnr   )r   r+  r}  r  local_tabler   r   r   r   r   _equivalent_columnsr  r   r   r   rd  r   _columns_are_mappedr   r   remote_columnsr   r   foreign_key_columnsr   r   )r   jcs     r   r;  +RelationshipProperty._setup_join_conditionsg  s   $1 %
&*kk&D&D%
%)[[%C%C%
 %)KK$;$;%
 $(;;#:#:	%

 33<<%
 oo//88%
 //77@@%
  ${{>>%
 #kk==%
 &*%D%D%
  $66%
 ((%
 "66%
 %
 "]]*%
  "55!%
 	
r$ >>--"$"7"7,,--!#!5!5(*(>(>%+-+I+I(r   c                     U R                   S   $ )Nr   rQ  r   s    r   _clsregistry_resolve_arg-RelationshipProperty._clsregistry_resolve_arg       **1--r   c                     U R                   S   $ )Nr   r  r   s    r   r|  .RelationshipProperty._clsregistry_resolve_name  r  r   zsqlalchemy.orm.clsregistryc                    [         R                  R                  R                  nU" U R                  R
                  U 5      $ r   )r6   rz  orm_clsregistry	_resolverr+  r  )r   r  s     r   rQ  +RelationshipProperty._clsregistry_resolvers  s0     NN22<<	++T22r   c           	        U R                   R                  (       a  [        U R                   R                  SS9R	                  U R
                  5      (       di  [        R                  " SU R
                  < SU R                   R                  R                  < SU R                   R                  R                  < S35      egg)zGTest that this relationship is legal, warn about
inheritance conflicts.Fru  z)Attempting to assign a new relationship 'z$' to a non-primary mapper on class 'zm'.  New relationships can only be added to the primary mapper, i.e. the very first mapper created for class 'z' N)	r+  non_primaryr   r  has_propertyr	  r   r   r   r   s    r   r8  %RelationshipProperty._check_conflicts  s     ;;""<KK%,

,txx
 ,! && HHKK&&//KK&&//	 ,!"r   c                    U R                   $ )zLReturn the current cascade setting for this
:class:`.RelationshipProperty`.
)r  r   s    r   r   RelationshipProperty.cascade  s    
 }}r   c                &    U R                  U5        g r   )_set_cascader   r   s     r   r   r    s    '"r   c                   [        U5      nU R                  (       a(  [        UR                  [         R                  5      5      nSU R                  ;   a  U R                  U5        X l        U R                  (       a  X R                  l        g g )Nr  )	r/   r   intersection_viewonly_cascadesry  r<  r  r   r   )r   cascade_argr   s      r   r  !RelationshipProperty._set_cascade  sl     -==$$$^%F%FGG t}}$((1%%18&&. &r   c                   UR                   (       a  U R                  (       d  U R                  [        L d  U R                  [        L an  [
        R                  " SU U R                  [        L a  SOSU R                  R                  R                  U R                  R                  R                  S.-  SS9eU R                  S:X  a%  SU;   d  S	U;   a  [
        R                  " S
U -  5      eUR                   (       aT  U R                  R                  5       R                  R                  U R                  U R                  R                  45        g g )Na  For %(direction)s relationship %(rel)s, delete-orphan cascade is normally configured only on the "one" side of a one-to-many relationship, and not on the "many" side of a many-to-one or many-to-many relationship.  To force this relationship to allow a particular "%(relatedcls)s" object to be referenced by only a single "%(clsname)s" object at a time via the %(rel)s relationship, which would allow delete-orphan cascade to take place in this direction, set the single_parent=True flag.zmany-to-onezmany-to-many)relr   clsname
relatedclsbbf0codeallr  r  z^On %s, can't set passive_deletes='all' in conjunction with 'delete' or 'delete-orphan' cascade)delete_orphanr   r   r'   r(   r   r   r+  r  r   r  r   primary_mapper_delete_orphansr  r	  r  s     r   r<  ,RelationshipProperty._check_cascade_settings  s   !!&&:-91L&&/    >>Y6 &+#{{11::"&++"4"4"="=	. 1 6 5(?g#=&&;=AB 
   KK&&(88??4;;--. !r   c                x    U R                   UR                  ;   =(       a    UR                  U R                      U L $ )zQReturn True if this property will persist values on behalf
of the given mapper.

)r	  relationshipsr
  s     r   _persists_for"RelationshipProperty._persists_for  s7     HH,,, 7$$TXX.$6	
r   c                d   U R                   R                  R                  nU H  nUb"  UR                  R	                  U5      (       a  M(  U R
                  R                  R                  R	                  U5      (       a  M^  U R                  R                  R	                  U5      (       a  M    g   g)zReturn True if all columns in the given collection are
mapped by the tables referenced by this :class:`.RelationshipProperty`.

FT)r   r   r   r  contains_columnr+  r}  r~  )r   colsr   r  s       r   r  (RelationshipProperty._columns_are_mapped  s     OO--66	A$)D)DQ)G)G;;1133CC kkmm33A66  r   c           
        U R                   R                  (       a  gU R                  Gb  U R                  (       Gd~  [	        U R                  [
        5      (       a  U R                  0 p!OU R                  u  pU R                  R                  5       nUR                  (       d  [        UR                  5       5      R                  UR                  5      nU HO  nUR                  U5      (       d  M  UR                  (       a  M.  [        R                  " SU< SU < SU< S35      e   U R                   bM  UR#                  SU R$                  R&                  5      nUR#                  SU R$                  R(                  5      nOUUR#                  SU R$                  R*                  5      nUR#                  SS5      nU(       a  [        R,                  " S5      eUR#                  S	U R.                  5      nU R                   R                  5       n	UR1                  S
U R2                  5        UR1                  SU R4                  5        UR1                  SU R6                  5        UR1                  SU R8                  5        Xl        [;        U	U R                   4UUUU R<                  S.UD6n
UR?                  XSS9  U R                  (       a  U RA                  U R                  5        gg)zdInterpret the 'backref' instruction to create a
:func:`_orm.relationship` complementary to this one.NzError creating backref 'z' on relationship 'z+': property of that name exists on mapper 'r  r   r   zOCan't assign 'secondaryjoin' on a backref against a non-secondary relationship.r   r   r   r   r   )r   r   r   r   T)warn_for_existing)!r+  r  r   r   r   r   r  r  concreter   iterate_to_rootunionself_and_descendantsr  r   r   r   popr   secondaryjoin_minus_localprimaryjoin_minus_localprimaryjoin_reverse_remoter[  r   
setdefaultr   r   r   r   r   r	  _configure_propertyr1  )r   backref_keyrp  r  checkmr6  r7  r   r+  relationships              r   r>  &RelationshipProperty._generate_backref  st    ;;""<<#D,?,?,?$,,,,&*llBV&*ll#[[//1F??F2245;;// A~~k221:::$22  +D!5   ~~) ZZ!((BB ZZ#((@@
 ZZ!((CC ZZ6 44@ 
 ":: ? ?L [[//1Fj$--8mT-=-=>/1E1EFnd.?.?@"-/  )#xx L &&T '  &&t':':; r   zsqlalchemy.orm.dependencyc                    [         R                  R                  nU R                  c  U R                  [
        LU l        U R                  (       d!  UR                  R                  U 5      U l	        g g r   )
r6   rz  orm_dependencyr   r   r(   r   rZ   from_relationshipr   )r   
dependencys     r   r=  RelationshipProperty._post_initc  sV    ^^22
<<>>:DL}}..@@0 & r   c                2    U R                   nUR                  $ )zHmemoize the 'use_get' attribute of this RelationshipLoader's
lazyloader.)r   use_get)r   strategys     r   r  RelationshipProperty._use_getn  s    
 &&r   c                L    U R                   R                  U R                  5      $ r   )r  r/  r+  r   s    r   rd  )RelationshipProperty._is_self_referentialv  s    {{((55r   c                   SnU(       a  U R                   b  SnUc8  U(       a1  U R                  R                  (       a  U R                  R                  nU(       a  UR                  nUc  UR
                  nSnOU R                  nUcZ  U R                  R
                  nU R                  R                  (       a  SnU R                  (       a  Uc  UR                  5       nSnO5X0R                  R                  Ld  U R                  R                  (       a  SnUR                  n	U=(       d6    US L=(       a+    UU R                  R                  L=(       d    UR                  nU R                  R                  UUUU	U5      u  n
nnnnUc  U R                  R                  nUc  U R                  R                  nU
UUUUU4$ )NFT)r   r+  with_polymorphicr,  r  r*  r  rd  re  rf  _is_subqueryr   join_targetsr  )r   r1  r0  r_  r2  r3  r  aliaseddest_mapperrt  r   r   r   r:  s                 r   r4  "RelationshipProperty._create_joinsz  s     t~~9G$!dkk&B&B$(KK$L$L!(//K&"0";";++K""kk44O{{++((->-F"1"G"G"I;;#K#KK{{++G!99 
T) !{{??@ 2$11 	   --
	
 $ $ 7 7""kk55O
 	
r   ).r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r~  r   r   )NN)Hr   z'Optional[_RelationshipArgumentType[_T]]r   z(Optional[_RelationshipSecondaryArgument]r   Optional[bool]r   zEOptional[Union[Type[Collection[Any]], Callable[[], Collection[Any]]]]r   ,Optional[_RelationshipJoinConditionArgument]r   r  r   Optional[str]r   _ORMOrderByArgumentr   zOptional[ORMBackrefArgument]r   r  r   r   r   r   r   r   r   zOptional[_AttributeOptions]r   _LazyLoadArgumentTyper   zUnion[Literal['all'], bool]r   r   r   r   r   r   r   #Optional[_ORMColCollectionArgument]r   r  r   zOptional[int]r   z4Optional[Type[RelationshipProperty.Comparator[Any]]]r   r   r   r   r   r  r   r   r   zOptional[Type[Query[Any]]]r   zOptional[_InfoType]r   zLiteral[None, False]r   r  r   r  r   zLiteral[True]r   zLiteral[False]r   r   r   r   )r   r   r   r   )r  Mapper[Any]r   r   )TN)r  objectr3  r   r  zOptional[_EntityType[Any]]r   r   )FNT)
r  r   r  r   rU  Optional[_CoreAdapterProto]r3  r   r   r   )
r  r  r  r  r  rR   r  r   r   zCallable[[], Any])FN)r  r   rU  r  r   r   r   r   )r  r]   r  r  r  rR   r  r  r  rR   r  r   r  zDict[Any, object]r  z#Dict[_IdentityKeyType[Any], object]r   r   )
r  zInstanceState[_O]r  rR   r	  r   r  r"   r   z&Sequence[Tuple[InstanceState[_O], _O]]r   )r  r   r  r  r  rR   r  zSet[InstanceState[Any]]r  z.Optional[Callable[[InstanceState[Any]], bool]]r   zDIterator[Tuple[Any, Mapper[Any], InstanceState[Any], _InstanceDict]]r   )r'  RelationshipProperty[Any]r(  r  r   r   )r	  r   r   r   )r   z_InternalEntityType[_T])r   rt   r   r   )rf  rY   rD  rU   rg  z	Type[Any]rh  r  r	  r   ri  zOptional[Type[Mapped[Any]]]rj  Optional[_AnnotationScanType]rk  r  rl  r   r   r   )r  r   r   r   )r   r   )r   z>Callable[[str], Callable[[], Union[Type[Any], Table, _ModNS]]])r   zmTuple[Callable[[str], Callable[[], Union[Type[Any], Table, _ModNS]]], Callable[[str, bool], _class_resolver]])r   r/   )r   Union[str, CascadeOptions]r   r   )r  r  r   r   )r   r/   r   r   )r  r  r   r   )r  r   r   r   )FNNNFr   )r1  r   r0  r   r_  r   r2  z"Optional[_InternalEntityType[Any]]r3  r   r  r  r   zTuple[ColumnElement[bool], Optional[ColumnElement[bool]], FromClause, FromClause, Optional[FromClause], Optional[ClauseAdapter]])Ar   r   r   r   r   r   _RELATIONSHIP_TOKENstrategy_wildcard_keyinherit_cache_links_to_entity_is_relationshipr   r  r   r   r   r   r  r6   MemoizedSlotsr*   rr   r   r  rY  r  r  r  r  r"   r  r  r   r  r#  staticmethodr)  r1  memoized_propertyr  r  r@  r:  r9  rr  preload_moduler.  r;  r  r|  rQ  r8  r   setterr  r<  r  r  r>  r=  r  rd  r4  r   __classcell__)r   s   @r   r   r   5  s   	 -@@M <@8?$$00##""%% 7755((**##!77..$$!! =A>BH#
 #' DHFJ(,(-04"&!+9=&.7< $$"&<@;?$( #.2 %26$(*.'+!&*+06:/4UH#9H# <H#
  H#
H# BH# DH# &H# &H# .H#  H# H#  !H#" #H#$ 7%H#& $'H#( 5)H#* +H#, -H#.  /H#0 :1H#2 93H#4 "5H#6
7H#< =H#> ?H#@ ,AH#B CH#D 0EH#F "GH#H (IH#J %KH#L MH#N $OH#P )QH#R 4SH#T )-UH# H#T$
x	T'')< x	z !%26	

 
 0	

 

. !&48 $BB B 2	B
 B 
BHii "i 	i
 #i 
iZ #(48 2 
	,A__ )_ #	_
 '_ !_ _ &_  C_ 
_L  +667 7 7 	7
 7 
07> CG;D;D ";D 	;D
 0;D @;D 
N;Dz 2 2 '('1J'	' '*X 
  
" "


J
X`L)`L  `L 	`L
 *`L `L 6`L 2`L &C`L !`L 
`LD 
01-5 2-5^J< .	/. .
 .	G. .
 
	563
3 7 3&   ^^# #9,\	
 N<` 
45 6 
    
6 6
 $)2604=A %:<Q
 Q
 0Q
 .	Q

 ;Q
 Q
 8Q

Q
 Q
r   r   c                6   ^^ SUU4S jjmU b  T" U 5      n S mU $ )Nc                   > [        U [        R                  5      (       a   U R                  TR                  " 5       5      n U R                  TS9  U $ )N)clone)r   r9   r@   rh  copy_copy_internals)elemr   r   s    r   r    _annotate_columns.<locals>.clone  sC    dJ3344>>+"2"2"45D5)r   )r  r   r   r   r   )elementr   r   s    `@r   r   r     s(      .ENr   c                     \ rS rSr% S\S'   S\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   SSSSSSSSSSS S.                               SES jjrSFS jrSFS jrSFS jr\	SGS  j5       r
\	SGS! j5       r\R                  SGS" j5       rSHS# jr\R                  SIS$ j5       r\R                  SIS% j5       rSFS& jrSFS' jrSFS( jrSIS) jrSIS* jrSFS+ jrSFS, jr      SJS- jrSFS. jrSFS/ jrSFS0 jrSFS1 jrSFS2 jrSFS3 jrSFS4 jr       SKS5 jr!SFS6 jr"    SLS7 jr#SFS8 jr$\%RL                  " 5       r'S9\S:'   SFS; jr(\R                  SMS< j5       r)\R                  SMS= j5       r*\R                  SMS> j5       r+    SNS? jr,      SOS@ jr-\R                  SPSA j5       r.  SQ           SRSB jjr/SSSTSC jjr0SDr1g)Ur   i  r   primaryjoin_initialr   r   r   r   r   r  r  r   r   r   r+   r   rk   r  r  r  r  r   r   NFTc                     gNTr   )r  s    r   <lambda>JoinCondition.<lambda>  s    4r   )r   r   r   r  r  r  r   r   r  r  r  c                  Xl         X0l        X l        X@l        Xl        Xl        XPl        Xpl        X`l        Xl	        Xl
        Xl        Xl        Xl        Xl        UU l        U R!                  5         U R"                  c   eU R%                  5         U R'                  5         U R)                  5         U R+                  5         U R-                  5         U R/                  5         U R1                  U R"                  S5        U R                  b  U R1                  U R                  S5        U R3                  5         U R5                  5         U R7                  5         g NTF)r  r  r  r  r  r  r  r   r   r  r   _remote_sider  r  r  r  _determine_joinsr   _sanitize_joins_annotate_fks_annotate_remote_annotate_local_annotate_parentmapper_setup_pairs_check_foreign_cols_determine_direction_check_remote_side
_log_joins)r   r  r  r  r  r   r   r   r  r  r  r   r   r  r  r  r  s                    r   r   JoinCondition.__init__  s%   ( *C&'>$(@%&<#"4!2#. *"(@%#5 '	 0( 0+++##%  !1!148)$$T%7%7?!!#!r   c           	        U R                   R                  nUR                  " SU R                   U R                  5        UR                  " SU R                   U R                  5        UR                  " SU R                   SR                  S U R                   5       5      5        UR                  " SU R                   SR                  S U R                  =(       d    /  5       5      5        UR                  " SU R                   SR                  S	 U R                   5       5      5        UR                  " S
U R                   SR                  S U R                   5       5      5        UR                  " SU R                   SR                  S U R                   5       5      5        UR                  " SU R                   U R                  5        g )Nz%s setup primary join %sz%s setup secondary join %sz%s synchronize pairs [%s],c              3  <   #    U  H  u  pS U< SU< S3v   M     g7f(z => rx  Nr   rC  lr   s      r   rE  +JoinCondition._log_joins.<locals>.<genexpr>)	  s      4J&1a1%4J   z#%s secondary synchronize pairs [%s]c              3  <   #    U  H  u  pS U< SU< S3v   M     g7fr  r   r   s      r   rE  r"  0	  s       DFQ !"1%Dr#  z%s local/remote pairs [%s]c              3  <   #    U  H  u  pS U< SU< S3v   M     g7f)r  z / rx  Nr   r   s      r   rE  r"  8	  s      3J!Qq!$3Jr#  z%s remote columns [%s]c              3  ,   #    U  H
  nS U-  v   M     g7fz%sNr   rC  r  s     r   rE  r"  ?	  s     ?+>CTCZ+>   z%s local columns [%s]c              3  ,   #    U  H
  nS U-  v   M     g7fr'  r   r(  s     r   rE  r"  D	  s     >+=CTCZ+=r)  z%s relationship direction %s)r  loggerr   r   r   joinr   r   r   r  r   r   )r   r3   s     r   r  JoinCondition._log_joins"	  sm   ii+TYY8H8HI-tyy$:L:LM'IIHH 484J4J 	
 	1IIHH ">>D"D 	
 	(IIHH 373J3J 	
 	$IIHH?4+>+>??	

 	#IIHH>4+=+=>>	

 	/DNNKr   c                    [        U R                  SS9U l        U R                  b  [        U R                  SS9U l        gg)a7  remove the parententity annotation from our join conditions which
can leak in here based on some declarative patterns and maybe others.

"parentmapper" is relied upon both by the ORM evaluator as well as
the use case in _join_fixture_inh_selfref_w_entity
that relies upon it being present, see :ticket:`3364`.

)r  	proxy_keyvaluesN)rD   r   r   r   s    r   r  JoinCondition._sanitize_joinsH	  sI     ,%B
 )!1""+H"D *r   c                p   U R                   b0  U R                  c#  [        R                  " SU R                  -  5      e U R
                  =(       d    SnU R                  b  U R                   c/  [        U R                  U R                  U R                  US9U l         U R                  c0  [        U R                  U R                  U R                  US9U l        gU R                  U l        gU R                  c0  [        U R                  U R                  U R                  US9U l        gU R                  U l        g! [        R                   aj  nU R                  b4  [        R                  " SU R                  < SU R                  < S35      Ue[        R                  " SU R                  -  5      UeSnAf[        R                   aj  nU R                  b4  [        R                  " SU R                  < SU R                  < S	35      Ue[        R                  " S
U R                  -  5      UeSnAff = f)zDetermine the 'primaryjoin' and 'secondaryjoin' attributes,
if not passed to the constructor already.

This is based on analysis of the foreign key relationships
between the parent and target mapped selectables.

NzMProperty %s specified with secondary join condition but no secondary argument)a_subsetr  zOCould not determine join condition between parent/child tables on relationship zG - there are no foreign keys linking these tables via secondary table 'z'.  Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify 'primaryjoin' and 'secondaryjoin' expressions.a  Could not determine join condition between parent/child tables on relationship %s - there are no foreign keys linking these tables.  Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.zP - there are multiple foreign key paths linking the tables via secondary table 'z'.  Specify the 'foreign_keys' argument, providing a list of those columns which should be counted as containing a foreign key reference from the secondary table to each of the parent and child tables.a'  Could not determine join condition between parent/child tables on relationship %s - there are multiple foreign key paths linking the tables.  Specify the 'foreign_keys' argument, providing a list of those columns which should be counted as containing a foreign key reference to the parent table.)r   r   r   r   r  r  rH   r  r  r  r  r  r   NoForeignKeysErrorAmbiguousForeignKeysError)r   r  nfeafes       r   r  JoinCondition._determine_joinsZ	  s    )dnn.D&&(*.))4 I	'+'D'D'L$~~)%%-)755!%!<!<1I	*D& ++3'566!%!=!=1I	(D$ (,'?'?D$++3'56655!%!=!=1I	(D$ (,'?'?D$(( 	~~)// '+iiA	 	 //: =AIIF  // 	~~)66 37))T^^M
 
 66A DH99M 	s8   BD; D; ,<D; )D; ;H5A%F44H5A%H00H5c                *    [        U R                  SS9$ Nlocalr   r0  )rD   r   r   s    r   r  %JoinCondition.primaryjoin_minus_local	  s     0 09LMMr   c                H    U R                   c   e[        U R                   SS9$ r;  )r   rD   r   s    r   r  'JoinCondition.secondaryjoin_minus_local	  s(    !!--- 2 2;NOOr   c                    U R                   (       a'  SS jn[        R                  " U R                  0 U5      $ U R                  (       a  [        U R                  SS9$ [        U R                  5      $ )zReturn the primaryjoin condition suitable for the
"reverse" direction.

If the primaryjoin was delivered here with pre-existing
"remote" annotations, the local/remote annotations
are reversed.  Otherwise, the local/remote annotations
are removed.

c                    SU R                   ;   a.  [        U R                   5      nUS	 SUS'   U R                  U5      $ SU R                   ;   a.  [        U R                   5      nUS	 SUS'   U R                  U5      $ g )Nr   Tr=  )_annotationsr  _with_annotations)r  r   r  s      r   replace9JoinCondition.primaryjoin_reverse_remote.<locals>.replace	  s    w333W112A(!%AgJ"44Q77 4 44W112A'
"&AhK"44Q77r   r<  r0  r  r   r   r   r   zOptional[_CE])_has_remote_annotationsr<   replacement_traverser   _has_foreign_annotationsrD   )r   rE  s     r   r  (JoinCondition.primaryjoin_reverse_remote	  sd     '' 001A1A2wOO,,'$$-@  ((8(899r   c                b    [         R                  " U0 5       H  nX#R                  ;   d  M    g   gr  )r<   iteraterC  )r   rD  rj  r  s       r   _has_annotationJoinCondition._has_annotation	  s-    ##FB/C--- 0 r   c                :    U R                  U R                  S5      $ Nr   rN  r   r   s    r   rJ  &JoinCondition._has_foreign_annotations	  s    ##D$4$4i@@r   c                :    U R                  U R                  S5      $ Nr   rR  r   s    r   rH  %JoinCondition._has_remote_annotations	  s    ##D$4$4h??r   c                    U R                   (       a  gU R                  (       a  U R                  5         gU R                  5         g)zyAnnotate the primaryjoin and secondaryjoin
structures with 'foreign' annotations marking columns
considered as foreign.

N)rJ  r  _annotate_from_fk_list_annotate_present_fksr   s    r   r  JoinCondition._annotate_fks	  s1     (((('')&&(r   c                   ^  SU 4S jjn[         R                  " T R                  0 U5      T l        T R                  b(  [         R                  " T R                  0 U5      T l        g g )Nc                L   > U TR                   ;   a  U R                  SS05      $ g Nr   T)r  rh  r  r   r   s     r   check_fk6JoinCondition._annotate_from_fk_list.<locals>.check_fk
  s*    $777(()T):;;r   rG  )r<   rI  r   r   )r   r_  s   ` r   rX  $JoinCondition._annotate_from_fk_list
  s]    	
 $88b(
 )!)!>!>""B"D *r   c                x  ^^ U R                   b+  [        R                  " U R                   R                  5      mO
[	        5       m      SU4S jjmSU4S jjn[
        R                  " U R                  0 SU05      U l        U R                  b*  [
        R                  " U R                  0 SU05      U l        g g )Nc                (  > [        U [        R                  5      (       aO  [        U[        R                  5      (       a0  U R                  U5      (       a  U $ UR                  U 5      (       a  U$ T(       a  U T;   a  UT;  a  U $ UT;   a  U T;  a  U$ g r   )r   r4   Column
references)absecondarycolss     r   
is_foreign7JoinCondition._annotate_present_fks.<locals>.is_foreign
  sx     !V]]++
1fmm0L0L<<??H\\!__H%!=*@H-'A],BHr   binaryc                f  > [        U R                  [        R                  5      (       a)  [        U R                  [        R                  5      (       d  g SU R                  R
                  ;  a  SU R                  R
                  ;  a  T" U R                  U R                  5      nUb  UR                  U R                  5      (       a#  U R                  R                  SS05      U l        g UR                  U R                  5      (       a#  U R                  R                  SS05      U l        g g g g g r]  )r   leftr5   rA   rightrC  comparerh  )rk  r  ri  s     r   visit_binary9JoinCondition._annotate_present_fks.<locals>.visit_binary)
  s    S.. c.?.?@@ !9!99V\\%>%>> fll;?{{6;;//&,kk&;&;Y<M&NV\\22'-||'='=&-( 3 # ? :r   )rf  r   rg  r   r   zOptional[ColumnElement[Any]]rk  BinaryExpression[Any]r   r   )	r   r6   rS  r  r   r<   r  r   r   )r   rp  ri  rh  s     @@r   rY  #JoinCondition._annotate_present_fks
  s    >>% OODNN,<,<=MEM	!	&8	)	"	& $33b8\":
 )!)!9!9""B<(@"D *r   c                   ^^^ U R                   mU R                  mSmSUUU4S jjn[        R                  " U R                  0 SU05        T$ )zfReturn True if the join condition contains column
comparisons where both columns are in both tables.

Frk  c                  > U R                   U R                  p![        U[        R                  5      (       a  [        U[        R                  5      (       a  TR                  UR                  5      (       af  TR                  UR                  5      (       aE  TR                  UR                  5      (       a$  TR                  UR                  5      (       a  Smg g g g g g g r	  )rm  rn  r   r9   r@   is_derived_fromtable)rk  r  fmtptresults      r   rp  ;JoinCondition._refers_to_parent_table.<locals>.visit_binaryM
  s    ;;q1j5566q*"9"9::&&qww//&&qww//&&qww//&&qww// 0 0 0 0 ; 7r   rr  )r  r  r<   rg  r   )r   rp  rz  r{  r|  s     @@@r   _refers_to_parent_table%JoinCondition._refers_to_parent_tableD
  sN    
 ++**	 	 	$**B<0HIr   c                B    [        U R                  U R                  5      $ )z5Return True if parent/child tables have some overlap.)rI   r  r  r   s    r   _tables_overlapJoinCondition._tables_overlap]
  s"     #**D,I,I
 	
r   c                   U R                   (       a  gU R                  b  U R                  5         gU R                  (       d  U R                  (       a  U R                  5         gU R                  5       (       a  U R                  S S5        gU R                  5       (       a  U R                  5         gU R                  5         g)zAnnotate the primaryjoin and secondaryjoin
structures with 'remote' annotations marking columns
considered as part of the 'remote' side.

Nc                     SU R                   ;   $ rQ  )rC  )r  s    r   r
  0JoinCondition._annotate_remote.<locals>.<lambda>s
  s    I)9)99r   F)rH  r   _annotate_remote_secondaryr   r  _annotate_remote_from_argsr~  _annotate_selfrefr  _annotate_remote_with_overlap%_annotate_remote_distinct_selectablesr   s    r   r  JoinCondition._annotate_remoted
  s     ''>>%++-%%):):++-))++""95 !!##..0668r   c                  ^ U R                   c   eU R                   mSU4S jjn[        R                  " U R                  0 U5      U l        U R                  c   e[        R                  " U R                  0 U5      U l        g)zNannotate 'remote' in primaryjoin, secondaryjoin
when 'secondary' is present.

Nc                l   > TR                   R                  U 5      (       a  U R                  SS05      $ g Nr   T)r  r  rh  )r  r   fixed_secondarys     r   repl6JoinCondition._annotate_remote_secondary.<locals>.repl
  s3      0099(((D)9::r   rG  )r   r<   rI  r   r   )r   r  r  s     @r   r  (JoinCondition._annotate_remote_secondaryz
  sy     ~~)))..	
 $88b$
 !!---%::D
r   c                p   ^ ^^ SUUU 4S jjn[         R                  " T R                  0 SU05      T l        g)zhannotate 'remote' in primaryjoin, secondaryjoin
when the relationship is detected as self-referential.

rk  c                  > U R                   R                  U R                  5      n[        U R                   [        R
                  5      (       a  [        U R                  [        R
                  5      (       a|  T" U R                   5      (       a"  U R                   R                  SS05      U l         T" U R                  5      (       a+  U(       d#  U R                  R                  SS05      U l        g g g T(       d  TR                  5         g g r  )rm  ro  rn  r   r9   r@   rh  _warn_non_column_elements)rk  equatedfnremote_side_givenr   s     r   rp  5JoinCondition._annotate_selfref.<locals>.visit_binary
  s    kk))&,,7G&++z'>'>??Jj55E E fkk??"(++"7"748H"IFKfll##G#)<<#9#98T:J#KFL -4#&..0 'r   Nrr  )r<   r  r   )r   r  r  rp  s   ``` r   r  JoinCondition._annotate_selfref
  s4    	1 	1 $33b8\":
r   c                  ^ U R                   (       aI  U R                  (       a  [        R                  " S5      eU R                    VVs/ s H  u  pUPM	     snnmOU R                  mU R	                  5       (       a  U R                  U4S jS5        gSU4S jjn[        R                  " U R                  0 U5      U l        gs  snnf )zuannotate 'remote' in primaryjoin, secondaryjoin
when the 'remote_side' or '_local_remote_pairs'
arguments are used.

zTremote_side argument is redundant against more detailed _local_remote_side argument.c                   > U T;   $ r   r   )r  r   s    r   r
  :JoinCondition._annotate_remote_from_args.<locals>.<lambda>
  s
    sk/Ar   Tc                J   > U [        T5      ;   a  U R                  SS05      $ g r  )r   rh  )r  r   r   s     r   r  6JoinCondition._annotate_remote_from_args.<locals>.repl
  s+     c+..",,h-=>>r   NrG  )	r   r  r   r   r~  r  r<   rI  r   )r   r!  r   r  r   s       @r   r  (JoinCondition._annotate_remote_from_args
  s     ##  **   ,0+C+CD+C!1+CDK++K''))""#A4H  (<<  "d D Es   	Cc                  ^ ^^ SU4S jjnT R                   SL=(       a,    T R                   R                  T R                   R                  Lm      SUU 4S jjm[        R                  " T R
                  0 SU05      T l        g)zannotate 'remote' in primaryjoin, secondaryjoin
when the parent/child tables have some set of
tables in common, though is not a fully self-referential
relationship.

rk  c                   > T" U R                   U R                  5      u  U l         U l        T" U R                  U R                   5      u  U l        U l         g r   )rm  rn  )rk  proc_left_rights    r   rp  AJoinCondition._annotate_remote_with_overlap.<locals>.visit_binary
  sE    (7V\\)%FK )8fkk)%FL&+r   Nc                  > [        U [        R                  5      (       a  [        U[        R                  5      (       aj  TR                  R                  R                  U5      (       a=  TR                  R                  R                  U 5      (       a  UR                  SS05      nX4$ T(       aH  UR                  R                  S5      TR                  R                  L a  UR                  SS05      nX4$ T(       aH  U R                  R                  S5      TR                  R                  L a  U R                  SS05      n X4$ TR                  5         X4$ )Nr   Tr  )r   r9   r@   r  r  r  r  rh  rC  r  r  r  r  )rm  rn  check_entitiesr   s     r   r  DJoinCondition._annotate_remote_with_overlap.<locals>.proc_left_right
  s-    $
 7 788Zz..> > 0022BB 4466FFtLL!OOXt,<=E ; &&**>:dii>N>NN4(89 ; %%)).9TYY=M=MM~~x&67 ; ..0;r   rr  )rm  r   rn  r   r   z-Tuple[ColumnElement[Any], ColumnElement[Any]])r  r  r+  r<   r  r   )r   rp  r  r  s   ` @@r   r  +JoinCondition._annotate_remote_with_overlap
  s    	 IIT!Ndii&6&6dii>N>N&N 		$	-?	:	 	2 $33b8\":
r   c                d   ^  SU 4S jjn[         R                  " T R                  0 U5      T l        g)zeannotate 'remote' in primaryjoin, secondaryjoin
when the parent/child tables are entirely
separate.

c                (  > TR                   R                  R                  U 5      (       ag  TR                  R                  R                  U 5      (       a*  TR                  R                  R                  U 5      (       a  U R                  SS05      $ g r  )r  r  r  r  r  rh  r^  s     r   r  AJoinCondition._annotate_remote_distinct_selectables.<locals>.repl  ss    ,,..>>wGG0022BB7KK..00@@II(((D)9::r   NrG  r<   rI  r   )r   r  s   ` r   r  3JoinCondition._annotate_remote_distinct_selectables
  s*    	 $88b$
r   c                J    [         R                  " SU R                  -  5        g )NzNon-simple column elements in primary join condition for property %s - consider using remote() annotations to mark the remote side.)r6   r   r  r   s    r   r  'JoinCondition._warn_non_column_elements  s     		<>BiiH	
r   c                  ^ U R                  U R                  S5      (       a  gU R                  (       a6  [        R                  " U R                   VVs/ s H  u  pUPM	     snn5      mO*[        R                  " U R
                  R                  5      mSU4S jjn[        R                  " U R                  0 U5      U l        gs  snnf )a  Annotate the primaryjoin and secondaryjoin
structures with 'local' annotations.

This annotates all column elements found
simultaneously in the parent table
and the join condition that don't have a
'remote' annotation set up from
_annotate_remote() or user-defined.

r=  Nc                X   > SU R                   ;  a  U T;   a  U R                  SS05      $ g )Nr   r=  T)rC  rh  )r  r   
local_sides     r   locals_.JoinCondition._annotate_local.<locals>.locals_+  s0    w333:8M(('499r   rG  )	rN  r   r   r6   rS  r  r  r<   rI  )r   r!  r   r  r  s       @r   r  JoinCondition._annotate_local  s      0 0'::##!%!9!9:!9v!9:J )G)G)I)IJJ	
 $88b'
 ;s   C
c                d   ^  SU 4S jjn[         R                  " T R                  0 U5      T l        g )Nc                   > SU R                   ;   a'  U R                  STR                  R                  05      $ SU R                   ;   a'  U R                  STR                  R                  05      $ g )Nr   r  r=  )rC  rh  r  r  r+  r^  s     r   parentmappers_<JoinCondition._annotate_parentmapper.<locals>.parentmappers_5  sb    7///((.$)):J:J)KLLG000((.$)):J:J)KLLr   rG  r  )r   r  s   ` r   r  $JoinCondition._annotate_parentmapper4  s*    	 $88b.
r   c                x   U R                   (       d%  [        R                  " SU R                  < S35      e[        R
                  " U R                  R                  5      R                  U R                  R                  5      nU R                    H'  u  p#X1;   d  M  [        R                  " SU< S35        M)     g )Nr&  a   could not determine any unambiguous local/remote column pairs based on join condition and remote_side arguments.  Consider using the remote() annotation to accurately mark those elements of the join condition that are on the remote side of the relationship.zExpression z is marked as 'remote', but these column(s) are local to the local side.  The remote() annotation is needed only for a self-referential relationship where both sides of the relationship refer to the same tables.)r   r   r   r  r6   rS  r  r  
differencer  r   )r   
not_target_rmts       r   r   JoinCondition._check_remote_side@  s    &&&& (,yy3	 	 ..00j66889  11$II ! 2r   c                X   U R                  US5      n[        U5      nU(       a  [        U R                  5      nO[        U R                  5      nU R                  (       a  U(       d  U R                  (       d  U(       a  gU R                  (       aT  U(       aM  U(       dF  SU=(       a    S=(       d    S< SU< SU R
                  < S3nUS	-  n[        R                  " U5      eS
U=(       a    S=(       d    S< SU< SU R
                  < S3nUS-  n[        R                  " U5      e)z@Check the foreign key columns collected and emit error
messages.r   NzbCould not locate any simple equality expressions involving locally mapped foreign key columns for primaryr   z join condition 'z' on relationship r  a    Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or are annotated in the join condition with the foreign() annotation. To allow comparison operators other than '==', the relationship can be marked as viewonly=True.z6Could not locate any relevant foreign key columns for z  Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or are annotated in the join condition with the foreign() annotation.)_gather_columns_with_annotationr   r   r   r  r  r   r   )r   rH   r  foreign_colshas_foreigncan_syncerrs          r   r  !JoinCondition._check_foreign_cols\  s	   
 ;;I
 <(D223HD<<=H %%+
 X )	8[8"II  IC &&s++ )	8[8"II  C &&s++r   c                   U R                   b  [        U l        g[        R                  " U R
                  R                  5      n[        R                  " U R                  R                  5      nUR                  U R                  5      nUR                  U R                  5      nU(       Ga  U(       Ga  U R                  U R                  SS5      nU R                  U R                  S5       Vs1 s H  nSUR                  ;  d  M  UiM     nnU(       aN  U(       aG  U R                  R                  U R                  5      nUR                  U5      nUR                  U5      nU(       a  U(       d  [         U l        gU(       a  U(       d  ["        U l        g[$        R&                  " SU R(                  -  5      eU(       a  [         U l        gU(       a  ["        U l        g[$        R&                  " SU R(                  -  5      es  snf )zKDetermine if this relationship is one to many, many to one,
many to many.

Nr   r   aD  Can't determine relationship direction for relationship '%s' - foreign key columns within the join condition are present in both the parent and the child's mapped tables.  Ensure that only those columns referring to a parent column are marked as foreign, either via the foreign() annotation or via the foreign_keys argument.zCan't determine relationship direction for relationship '%s' - foreign key columns are present in neither the parent nor the child's mapped tables)r   r'   r   r6   rS  r  r  r  r  r  r  r   rC  r  r   r  r)   r(   r   r   r  )	r   
parentcols
targetcolsonetomany_fkmanytoone_fkonetomany_localr  manytoone_localself_equateds	            r   r  "JoinCondition._determine_direction  s   
 )'DN)G)G)I)IJJ)F)F)H)HIJ &2243K3KLL &2243K3KLL #'"F"F$$h	# "AA(()#  q~~5	    # ##'#6#6#C#C**$L '6&@&@&NO&5&@&@&NO #?%.DN$_%.DN ..9 <@99E	 	 !*!***4 7;ii@ U#s   /HHc                x    U VVs/ s H%  u  p#UR                  5       UR                  5       4PM'     snn$ s  snnf )zprovide deannotation for the various lists of
pairs, so that using them in hashes doesn't incur
high-overhead __eq__() comparisons against
original columns mapped.

)_deannotate)r   r  r  r  s       r   _deannotate_pairsJoinCondition._deannotate_pairs  s1     @JJztq!--/2zJJJs   ,6c                B  ^ ^ / n[         R                  " / 5      m/ n      SUU 4S jjnT R                  U4T R                  U44 H  u  pEUc  M
  U" XE5        M     T R	                  T5      T l        T R	                  U5      T l        T R	                  U5      T l        g )Nc                B   >^         SUUU4S jjn[        X 5        g )Nc                  > SUR                   ;   a9  SUR                   ;  a)  TR                  U5      (       a  TR                  X45        OHSUR                   ;   a8  SUR                   ;  a(  TR                  U5      (       a  TR                  X!45        U R                  [        R
                  L a^  TR                  X5      (       aG  SUR                   ;   a  TR                  X45        g SUR                   ;   a  TR                  X!45        g g g g )Nr   r   )rC  r  r  operatorr:   eqr  )rk  rm  rn  r  lrpr   s      r   rp  <JoinCondition._setup_pairs.<locals>.go.<locals>.visit_binary  s      2 22 (9(99--d33GGTM* 1 11 (:(::--e44GGUM*??ill2t7L7L8 8 !E$6$66"))4-8"d&7&77"))5-8 882r   )rk  rs  rm  r   rn  r   r   r   rJ   )joincondr  rp  r  r   s    ` r   go&JoinCondition._setup_pairs.<locals>.go  s;    9-9(9 *9 	9 92 !8r   )r  r   r  _MutableColumnPairsr   r   )r6   
OrderedSetr   r   r  r   r   r   )r   
sync_pairssecondary_sync_pairsr  r  r  r  s   `     @r   r  JoinCondition._setup_pairs  s    *,
OOB 	 57	9)	9+	9 	9 	9@ z*!56%
 H x$%
 #'"8"8"=!%!7!7
!C+/+A+A ,
(r   zwweakref.WeakKeyDictionary[ColumnElement[Any], weakref.WeakKeyDictionary[RelationshipProperty[Any], ColumnElement[Any]]]_track_overlapping_sync_targetsc                  ^ U R                   (       d  g U R                   VVs/ s H  u  pX4PM
     snnU R                   VVs/ s H  u  pX4PM
     snn-    GH  u  nmTU R                  ;  a1  [        R
                  " U R                  U05      U R                  T'   MH  / nU R                  T   nUR                  5        GH   u  pVUR                  R                  (       a  M#  XPR                  R                  ;  d  M>  UR                  U R                  R                  ;  d  Md  U R                  R                  UR                  ;  d  M  SU R                  R                  ;  d  M  SUR                  ;  d  M  U R                  R                  R                  UR                  5      (       a  M  U R                  R                  R                  UR                  5      (       a  GM%  U R                  R                  R                  UR                  5      (       a  GM\  U R                  R                  R                  UR                  5      (       a  GM  U R                  R                  UR                  :w  d7  U R                  R                  R                  UR                  5      (       a  GM  UR!                  XV45        GM     U(       a  ["        R$                  " SU R                  < SU< ST< SSR'                  [)        U4S jU 5       5      5      < SS	R'                  [)        S
 U 5       5      5      < SU R                  < S3SS9  XR                  T   U R                  '   GM     g s  snnf s  snnf )Nz__*rw  z' will copy column z to column z(, which conflicts with relationship(s): z, c              3  F   >#    U  H  u  pS U< SU< ST< S3v   M     g7f)r  z
' (copies z to rx  Nr   )rC  prfr_to_s      r   rE  CJoinCondition._warn_for_conflicting_sync_targets.<locals>.<genexpr>  s%      '"5@	S ACC$M5@s   !a  . If this is not the intention, consider if these relationships should be linked with back_populates, or if viewonly=True should be applied to one or more if they are read-only. For the less common case that foreign key constraints are partially overlapping, the orm.foreign() annotation can be used to isolate the columns that should be written towards.   To silence this warning, add the parameter 'overlaps="r  c              3  >   #    U  H  u  pUR                   v   M     g 7fr   )r	  )rC  r  frs      r   rE  r    s     +MvrBFFs   z"' to the 'z' relationship.qzyxr  )r  r   r   r  weakrefWeakKeyDictionaryr  r   r  _dispose_calledr   r	  r   r+  
is_siblingr/  r  r6   r   r,  sorted)r   from_r  other_propsprop_to_fromr  r  s     `    r   r?  0JoinCondition._warn_for_conflicting_sync_targets5  s      .2-C-C
-C\eUL-C
 .2-M-M
-M\eUL-M

JE3 $>>>--tyy%.@A 44S9 !#CCCH+113GBII555ii&A&AAFF$))*=*== IIMM= ")<)<<!5 $		 0 0 ; ;BII F F $		 0 0 ; ;BII F F $		 0 0 ; ;BII F F $		 0 0 ; ;BII F F IIMMRVV3#'99#3#3#A#A"))#L#L $**B95/  42 II !II! II & '"5@'" !"  HHV+M+M%MN II14 $7: HM44S9$))DW
 

s   M2M8c                $    U R                  S5      $ rU  _gather_join_annotationsr   s    r   r  JoinCondition.remote_columns  s    ,,X66r   c                $    U R                  S5      $ )Nr=  r  r   s    r   r   JoinCondition.local_columns  s    ,,W55r   c                $    U R                  S5      $ rQ  r  r   s    r   r  !JoinCondition.foreign_key_columns  s    ,,Y77r   c                   [        U R                  U R                  U5      5      nU R                  b+  UR	                  U R                  U R                  U5      5        U Vs1 s H  o3R                  5       iM     sn$ s  snf r   )r   r  r   r   r   r  )r   rj  sr  s       r   r  &JoinCondition._gather_join_annotations  su     001A1A:N
 )HH44&&

 *++A+++s   "A>c                    [        U5      n[        R                  " U0 5       Vs1 s H<  nUR                  UR                  5      (       d  M%  [        [        [           U5      iM>     sn$ s  snf r   )r   r<   rM  issubsetrC  r   rA   r   )r   rD  rj  annotation_setr  s        r   r  -JoinCondition._gather_columns_with_annotation  sc     Z  ''3
3&&s'7'78 *Ds#S)3
 	
 
s   $A+A+c                    U R                   bJ  [        [        R                  " U R                   R                   Vs/ s H  oR
                  PM     sn6 5      $ [        R                  $ s  snf r   )r   	frozenset	itertoolschainr  	proxy_setr6   	EMPTY_SETr   r  s     r   _secondary_lineage_set$JoinCondition._secondary_lineage_set  sT    >>%t~~7G7G!H7G!++7G!HI  >>! "Is   A(c                <  ^ ^ [        USS05      nT R                  T R                  T R                  pnUb  Ub  Xt-  nOXd-  nU(       aS        S
U 4S jjm[	        U4S jU 5       5      nUb  U[
        R                  " U6 -  nOU[
        R                  " U6 -  nU(       a  Ub  UR                  SS9n[        U[        S9n	[        UT R                  S9R                  U	5      n
Ub/  [        U[        S9R                  [        UT R                  S95      n	U
R                  U5      nOF[        U[        T R                  S	9n	Ub(  U	R                  [        U[        T R                  S	95        Sn
U	R                  U5      nU
=(       d    U	nSUl        OSnUUUUU4$ )a  Given a source and destination selectable, create a
join between them.

This takes into account aliasing the join clause
to reference the appropriate corresponding columns
in the target objects, as well as the extra child
criterion, equivalent column sets, etc.

ra  TNc                   > U R                   R                  SS5      nUTR                  R                  La4  UTR                  R                  La  U TR
                  ;  a  [        X5      $ U $ )znote unrelated columns in the "extra criteria" as either
should be adapted or not adapted, even though they are not
part of our "local" or "remote" side.

see #9779 for this case, as well as #11010 for a follow up

r  N)rC  r  r  r+  r  r  r?   )r  r   parentmapper_for_elementr   s      r   mark_exclude_cols5JoinCondition.join_targets.<locals>.mark_exclude_cols  se     ,0+<+<+@+@"D,(
 -DII4D4DD0		8H8HHD$?$??)$<<Kr   c              3  >   >#    U  H  n[        US S0TS9v   M     g7f)should_not_adaptT)annotate_callableNrB   )rC  r  r  s     r   rE  -JoinCondition.join_targets.<locals>.<genexpr>  s/      # +D '.&7
 +s   )flat)
exclude_fn)equivalents)r  r  )r  rf   r   re   r   rf   )rE   r   r   r   rG  r5   rK  re  rG   _local_col_excluder  r
  r  rg  _remote_col_excluder  )r   r0  r_  r  rt  r  r   r   r   primary_aliasizersecondary_aliasizerr:  r  s   `           @r   r  JoinCondition.join_targets  s   6 ,7>

 NN %. "( - ;)7 ) 8G $ 0 # # +# N ( -.0I I)CHHn,EE$%;;;F	$11%! '4#1G1G'%)* $ %0(5!#5) e%-(,(?(? & !4 < <] K$1#1 $ 6 6%!
 %0%++%-':(,(?(? '+#+44[AK0E4EN(,N%!N
 	
r   c                  ^^
^^ 0 m
0 nU R                   S LmT(       aI  [        R                  " [        5      mU R                   H  u  p4TU   R                  X445        X2U'   M      O:T(       d  U R                   H	  u  p4X2U'   M     OU R                   H	  u  p4XBU'   M           SU
UUU4S jjnU R                  nU R                   b  T(       d  [        R                  " U0 U5      nU R                   bA  U R                   nT(       a  [        R                  " U0 U5      n[        R                  " Xg5      nT
 Vs0 s H  nT
U   R                  U_M     n	nXiU4$ s  snf )Nc                   > T(       d  SU R                   ;   d+  T(       aS  T(       a  U T;   d  T(       d?  SU R                   ;   a/  U T;  a$  [        R                  " S S U R                  SS9TU '   TU    $ g )Nr=  r   T)r  r  )rC  r5   r  r  )r  r   bindshas_secondarylookupr  s     r   col_to_bind5JoinCondition.create_lazy_clause.<locals>.col_to_bindY  sj     '7g6J6J+J$"w&'8)h':N:N.N %'%(]]d',,t&E'N W~%r   )r  r   r   r   r   zOptional[BindParameter[Any]])r   collectionsdefaultdictlistr   r  r   r<   rI  r5   rK  r	  )r   r  equated_columnsr!  r   r&  	lazywherer   r  r  r#  r$  r%  s    `        @@@r   create_lazy_clause JoinCondition.create_lazy_clauseC  se   
 ?AHJ**$6 ,,T2F//q	  !(%&" 0 #//%&" 0 //%&" 0	'	/2	)	 	$ $$	%-> 552{I ) ..M  ( = =!2{! :I6;<esuSz~~s*e<66 =s   <E)r   r  r  r  r  r  r  r   r   r  r  r  r   r  r  r   r   r   r  r  r   ) r  rk   r  rk   r  rk   r  rk   r   r   r   r   r   r   r  Optional[_EquivalentColumnMap]r  r/  r  r   r   r   r   r   r  r   r  r  r  r   r  zCallable[..., bool]r  r  )rD  ri   rj  r   r   r   r   )r  z$Callable[[ColumnElement[Any]], bool]r  r   r   r   )rH   r   r  r   r   r   )r  _ColumnPairIterabler   r  )r   r   )rj  r   r   r   )rD  r   rj  zIterable[str]r   r   )r   zFrozenSet[ColumnElement[Any]])Nr   )r0  r   r_  rk   r  r   rt  r   r  r  r   ztTuple[ColumnElement[bool], Optional[ColumnElement[bool]], Optional[FromClause], Optional[ClauseAdapter], FromClause])F)r  r   r   zgTuple[ColumnElement[bool], Dict[str, ColumnElement[Any]], Dict[ColumnElement[Any], ColumnElement[Any]]])2r   r   r   r   r   r   r  r  r  r  r  r  r6   r  r  rN  rJ  rH  r  rX  rY  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r?  r  r   r  r  r  r  r  r-  r   r   r   r   r   r     so   66$$00##
####!--$$))((''&&// 6:*.7;=A<@(,59 %!0?%3#-3 #-3 ",	3
 !+3 33 (3 53 ;3 :3 #&3 33 3 3  (!3" #3$ .%3j$LL$]~ N N P P 
": ":H 
A A 
@ @)0d2
9,
.
6
KO
	
2B/
b
&

<

8?,1?,<@?,	?,BPd	K-	K		K2
r 	!!# $ & $TMl 
7 7 
6 6 
8 8,,	 ,
(
7D
	 
 
" " 6::<I
/I
 $I
 	I

 3I
 8I

I
V87 87r   r   c                  0    \ rS rSrSrSrSS jrSS jrSrg)	_ColInAnnotationsi~  zSerializable object that tests for names in c._annotations.

TODO: does this need to be serializable anymore?  can we find what the
use case was for that?

)namesc                $    [        U5      U l        g r   )r  r3  )r   r3  s     r   r   _ColInAnnotations.__init__  s    u%
r   c                ^    [        U R                  R                  UR                  5      5      $ r   )r   r3  r  rC  r  s     r   __call___ColInAnnotations.__call__  s     DJJ++ANN;<<r   N)r3  r   )r  ri   r   r   )	r   r   r   r   r   r   r   r7  r   r   r   r   r2  r2  ~  s     I&=r   r2  r=  r  r   c                      \ rS rSrSrSrSrg)Relationshipi  au  Describes an object property that holds a single item or list
of items that correspond to a related database table.

Public constructor is the :func:`_orm.relationship` function.

.. seealso::

    :ref:`relationship_config_toplevel`

.. versionchanged:: 2.0 Added :class:`_orm.Relationship` as a Declarative
   compatible subclass for :class:`_orm.RelationshipProperty`.

Tr   N)r   r   r   r   r   r  r   r   r   r   r:  r:    s     Mr   r:  c                  2    \ rS rSrSrSr \SS j5       rSrg)_RelationshipDeclaredi  z>Relationship subclass used implicitly for declarative mapping.Tc                    g)Nr:  r   )rg  s    r   _mapper_property_name+_RelationshipDeclared._mapper_property_name  s    r   r   Nr  )	r   r   r   r   r   r  classmethodr>  r   r   r   r   r<  r<    s"    
 IM r   r<  )r   r   r   r   )r  r   r   re   r   r   )r   
__future__r   r(  r   dataclassesr7   ra  r	  r   rd  r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _typingr   r   baser   r   r   r    r!   r"   r#   r$   
interfacesr%   r&   r'   r(   r)   r*   r+   r,   r6   r-   r.   r/   r1   r   r2   r3   r4   r5   
inspectionr8   r9   r:   r;   r<   sql._typingr=   r>   sql.annotationr?   sql.elementsr@   rA   sql.utilrC   rD   rE   rF   rG   rH   rI   rK   util.typingrL   rM   rN   TYPE_CHECKINGrO   rP   rQ   rR   rS   rT   rU   rV   clsregistryrW   rX   	decl_baserY   r  rZ   r  r[   queryr\   r  r]   r  r^   
strategiesr_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   
sql.schemarj   sql.selectablerk   rl   rm   rn   rp   rq   rr   rs   r   _RelationshipArgumentTyper  r   "_RelationshipJoinConditionArgument_RelationshipSecondaryArgumentr  ORMBackrefArgumentDMLColumnRole_ORMColCollectionElement_ORMColCollectionArgumentr   r   r0  r   r  r   r   	dataclassr   r   r   class_logger
Identifiedr   r   r   r2  r  r  r:  r<  r   r   r   <module>r^     s   #      	                        * . $ "   &   ! ) / " ! ! & - +  !                3 + + ' ( % ' ( . $ % * + 4 ! 9	$,)&,&,#1/ $&"!/2'04/,,"+13Te3e3e3vS! "HRb\RR##$&   
 " &+	"4	((& " "'#xL 011"  ENc"R*3//0R3C899:U31#6678:  3c4S>&9 ::;  c	  "%&R2334R))*	  v6s;<e/0 u]3%7s9K%KLM mC0-2DDEF5s!3]35G!GHI &( 'wsCx( ' ':  mC6H#6M0N NO 
 6 U
04cnnU
 U
p<
`7 `7F%= =" 'w0BC '2DE r,B"r   