Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/orm/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/orm/__pycache__/relationships.cpython-311.pyc

�

�܋f!��F�dZddlmZddlZddlZddlmZddlmZddlmZ	ddl
mZdd	l
mZdd
l
mZddl
mZddl
mZdd
l
mZddl
mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddl!m#Z#ddl!m$Z$ddl!m%Z%dd l!m&Z&dd!l!m'Z'dd"l!m(Z(d#�Z)d$�Z*ej+ej,�-d%d&�'��Gd(�d)e������Z.d*�Z/Gd+�d,e0��Z1Gd-�d.e0��Z2dS)/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`.

�)�absolute_importN�)�
attributes)�
dependency)�mapper)�_is_mapped_class)�	state_str)�
MANYTOMANY)�	MANYTOONE)�	ONETOMANY)�PropComparator)�StrategizedProperty)�
_orm_annotate)�_orm_deannotate)�CascadeOptions�)�exc)�log)�schema)�sql)�util)�inspect)�
expression)�	operators)�visitors)�_deep_deannotate)�_shallow_annotate)�adapt_criterion_to_null)�
ClauseAdapter)�join_condition)�selectables_overlap��visit_binary_productc�J�ttj|��ddi��S)aAnnotate 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_columnsr�_clause_element_as_expr��exprs �S/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/orm/relationships.pyr%r%4s+����*�4�0�0�8�T�2B����c�J�ttj|��ddi��S)aAnnotate 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.Gs+����*�4�0�0�9�d�2C���r,zsqlalchemy.orm.propertiesT)�
add_to_allc"���eZdZdZdZeddddd���ZdZej	d���ddddddddddddd	ded
eddeddddddded
eddddddddf!�fd�	��Z
d�Zd�ZGd�de
��Zd0d�Z			d1d�Zd�Zd2d�Zd�Zd�Zejfd�Z	d3d�Zed���Zed���Zd�Zejd���Zejd ���Z �fd!�Z!d"�Z"d#�Z#d$�Z$ed%���Z%e%j&d&���Z%d4d'�Z'd(�Z(d)�Z)d*�Z*d+�Z+d,�Z,ejd-���Z-ejd.���Z.						d5d/�Z/�xZ0S)6�RelationshipPropertyz�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`

    �relationshipFT��passive_deletes�passive_updates�enable_typechecks�active_history�cascade_backrefsN)z0.7z�:class:`.AttributeExtension` is deprecated in favor of the :class:`.AttributeEvents` listener interface.  The :paramref:`_orm.relationship.extension` parameter will be removed in a future release.)�	extension�selectr4r5r6r7r8c#���tt|�����||_||_||_||_||_|
|_d|_	|
|_
|
r|�|||||���|
r|"rtj
d���|"|_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_|!rt=jd��|!|_ ||_!||_"||_#||_$|ptj%|_&|�&|d��|_'t=j(|��| �| |_)d|jff|_*tW��|_,|dur||_-n|�.dd���||_/|	|_0|j0r|rtj
d	���d|_1dS||_1dS)
ah�Provide a relationship between two mapped classes.

        This corresponds to a parent-child or associative table relationship.
        The constructed class is an instance of
        :class:`.RelationshipProperty`.

        A typical :func:`_orm.relationship`, used in a classical mapping::

           mapper(Parent, properties={
             'children': relationship(Child)
           })

        Some arguments accepted by :func:`_orm.relationship`
        optionally accept a
        callable function, which when called produces the desired value.
        The callable is invoked by the parent :class:`_orm.Mapper` at "mapper
        initialization" time, which happens only when mappers are first used,
        and is assumed to be after all mappings have been constructed.  This
        can be used to resolve order-of-declaration and other dependency
        issues, such as if ``Child`` is declared below ``Parent`` in the same
        file::

            mapper(Parent, properties={
                "children":relationship(lambda: Child,
                                    order_by=lambda: Child.id)
            })

        When using the :ref:`declarative_toplevel` extension, the Declarative
        initializer allows string arguments to be passed to
        :func:`_orm.relationship`.  These string arguments are converted into
        callables that evaluate the string as Python code, using the
        Declarative class-registry as a namespace.  This allows the lookup of
        related classes to be automatic via their string name, and removes the
        need for related classes to be imported into the local module space
        before the dependent classes have been declared.  It is still required
        that the modules in which these related classes appear are imported
        anywhere in the application at some point before the related mappings
        are actually used, else a lookup error will be raised when the
        :func:`_orm.relationship`
        attempts to resolve the string reference to the
        related class.    An example of a string- resolved class is as
        follows::

            from sqlalchemy.ext.declarative import declarative_base

            Base = declarative_base()

            class Parent(Base):
                __tablename__ = 'parent'
                id = Column(Integer, primary_key=True)
                children = relationship("Child", order_by="Child.id")

        .. seealso::

          :ref:`relationship_config_toplevel` - Full introductory and
          reference documentation for :func:`_orm.relationship`.

          :ref:`orm_tutorial_relationship` - ORM tutorial introduction.

        :param argument:
          A mapped class, or actual :class:`_orm.Mapper` instance,
          representing
          the target of the relationship.

          :paramref:`_orm.relationship.argument`
          may also be passed as a callable
          function which is evaluated at mapper initialization time, and may
          be passed as a string name when using Declarative.

          .. warning:: Prior to SQLAlchemy 1.3.16, this value is interpreted
             using Python's ``eval()`` function.
             **DO NOT PASS UNTRUSTED INPUT TO THIS STRING**.
             See :ref:`declarative_relationship_eval` for details on
             declarative evaluation of :func:`_orm.relationship` arguments.

          .. versionchanged 1.3.16::

             The string evaluation of the main "argument" no longer accepts an
             open ended Python expression, instead only accepting a string
             class name or dotted package-qualified name.

          .. seealso::

            :ref:`declarative_configuring_relationships` - further detail
            on relationship configuration when using Declarative.

        :param secondary:
          For a many-to-many relationship, specifies the intermediary
          table, and is typically an instance of :class:`_schema.Table`.
          In less common circumstances, the argument may also be specified
          as an :class:`_expression.Alias` construct, or even a
          :class:`_expression.Join` construct.

          :paramref:`_orm.relationship.secondary` may
          also be passed as a callable function which is evaluated at
          mapper initialization time.  When using Declarative, it may also
          be a string argument noting the name of a :class:`_schema.Table`
          that is
          present in the :class:`_schema.MetaData`
          collection associated with the
          parent-mapped :class:`_schema.Table`.

          .. warning:: When passed as a Python-evaluable string, the
             argument is interpreted using Python's ``eval()`` function.
             **DO NOT PASS UNTRUSTED INPUT TO THIS STRING**.
             See :ref:`declarative_relationship_eval` for details on
             declarative evaluation of :func:`_orm.relationship` arguments.

          The :paramref:`_orm.relationship.secondary` keyword argument is
          typically applied in the case where the intermediary
          :class:`_schema.Table`
          is not otherwise expressed in any direct class mapping. If the
          "secondary" table is also explicitly mapped elsewhere (e.g. as in
          :ref:`association_pattern`), one should consider applying the
          :paramref:`_orm.relationship.viewonly` flag so that this
          :func:`_orm.relationship`
          is not used for persistence operations which
          may conflict with those of the association object pattern.

          .. seealso::

              :ref:`relationships_many_to_many` - Reference example of "many
              to many".

              :ref:`orm_tutorial_many_to_many` - ORM tutorial introduction to
              many-to-many relationships.

              :ref:`self_referential_many_to_many` - Specifics on using
              many-to-many in a self-referential case.

              :ref:`declarative_many_to_many` - Additional options when using
              Declarative.

              :ref:`association_pattern` - an alternative to
              :paramref:`_orm.relationship.secondary`
              when composing association
              table relationships, allowing additional attributes to be
              specified on the association table.

              :ref:`composite_secondary_join` - a lesser-used pattern which
              in some cases can enable complex :func:`_orm.relationship` SQL
              conditions to be used.

          .. versionadded:: 0.9.2 :paramref:`_orm.relationship.secondary`
             works
             more effectively when referring to a :class:`_expression.Join`
             instance.

        :param active_history=False:
          When ``True``, indicates that the "previous" value for a
          many-to-one reference should be loaded when replaced, if
          not already loaded. Normally, history tracking logic for
          simple many-to-ones only needs to be aware of the "new"
          value in order to perform a flush. This flag is available
          for applications that make use of
          :func:`.attributes.get_history` which also need to know
          the "previous" value of the attribute.

        :param backref:
          Indicates the string name of a property to be placed on the related
          mapper's class that will handle this relationship in the other
          direction. The other property will be created automatically
          when the mappers are configured.  Can also be passed as a
          :func:`.backref` object to control the configuration of the
          new relationship.

          .. seealso::

            :ref:`relationships_backref` - Introductory documentation and
            examples.

            :paramref:`_orm.relationship.back_populates` - alternative form
            of backref specification.

            :func:`.backref` - allows control over :func:`_orm.relationship`
            configuration when using :paramref:`_orm.relationship.backref`.


        :param back_populates:
          Takes a string name and has the same meaning as
          :paramref:`_orm.relationship.backref`, except the complementing
          property is **not** created automatically, and instead must be
          configured explicitly on the other mapper.  The complementing
          property should also indicate
          :paramref:`_orm.relationship.back_populates` to this relationship to
          ensure proper functioning.

          .. seealso::

            :ref:`relationships_backref` - Introductory documentation and
            examples.

            :paramref:`_orm.relationship.backref` - alternative form
            of backref specification.

        :param bake_queries=True:
          Use the :class:`.BakedQuery` cache to cache the construction of SQL
          used in lazy loads.  True by default.   Set to False if the
          join condition of the relationship has unusual features that
          might not respond well to statement caching.

          .. versionchanged:: 1.2
             "Baked" loading is the default implementation for the "select",
             a.k.a. "lazy" loading strategy for relationships.

          .. versionadded:: 1.0.0

          .. seealso::

            :ref:`baked_toplevel`

        :param cascade:
          A comma-separated list of cascade rules which determines how
          Session operations should be "cascaded" from parent to child.
          This defaults to ``False``, which means the default cascade
          should be used - this default cascade is ``"save-update, merge"``.

          The available cascades are ``save-update``, ``merge``,
          ``expunge``, ``delete``, ``delete-orphan``, and ``refresh-expire``.
          An additional option, ``all`` indicates shorthand for
          ``"save-update, merge, refresh-expire,
          expunge, delete"``, and is often used as in ``"all, delete-orphan"``
          to indicate that related objects should follow along with the
          parent object in all cases, and be deleted when de-associated.

          .. seealso::

            :ref:`unitofwork_cascades` - Full detail on each of the available
            cascade options.

            :ref:`tutorial_delete_cascade` - Tutorial example describing
            a delete cascade.

        :param cascade_backrefs=True:
          A boolean value indicating if the ``save-update`` cascade should
          operate along an assignment event intercepted by a backref.
          When set to ``False``, the attribute managed by this relationship
          will not cascade an incoming transient object into the session of a
          persistent parent, if the event is received via backref.

          .. seealso::

            :ref:`backref_cascade` - Full discussion and examples on how
            the :paramref:`_orm.relationship.cascade_backrefs` option is used.

        :param collection_class:
          A class or callable that returns a new list-holding object. will
          be used in place of a plain list for storing elements.

          .. seealso::

            :ref:`custom_collections` - Introductory documentation and
            examples.

        :param comparator_factory:
          A class which extends :class:`.RelationshipProperty.Comparator`
          which provides custom SQL clause generation for comparison
          operations.

          .. seealso::

            :class:`.PropComparator` - some detail on redefining comparators
            at this level.

            :ref:`custom_comparators` - Brief intro to this feature.


        :param distinct_target_key=None:
          Indicate if a "subquery" eager load should apply the DISTINCT
          keyword to the innermost SELECT statement.  When left as ``None``,
          the DISTINCT keyword will be applied in those cases when the target
          columns do not comprise the full primary key of the target table.
          When set to ``True``, the DISTINCT keyword is applied to the
          innermost SELECT unconditionally.

          It may be desirable to set this flag to False when the DISTINCT is
          reducing performance of the innermost subquery beyond that of what
          duplicate innermost rows may be causing.

          .. versionchanged:: 0.9.0 -
             :paramref:`_orm.relationship.distinct_target_key` now defaults to
             ``None``, so that the feature enables itself automatically for
             those cases where the innermost query targets a non-unique
             key.

          .. seealso::

            :ref:`loading_toplevel` - includes an introduction to subquery
            eager loading.

        :param doc:
          Docstring which will be applied to the resulting descriptor.

        :param extension:
          an :class:`.AttributeExtension` instance, or list of extensions,
          which will be prepended to the list of attribute listeners for
          the resulting descriptor placed on the class.

        :param foreign_keys:

          A list of columns which are to be used as "foreign key"
          columns, or columns which refer to the value in a remote
          column, within the context of this :func:`_orm.relationship`
          object's :paramref:`_orm.relationship.primaryjoin` condition.
          That is, if the :paramref:`_orm.relationship.primaryjoin`
          condition of this :func:`_orm.relationship` is ``a.id ==
          b.a_id``, and the values in ``b.a_id`` are required to be
          present in ``a.id``, then the "foreign key" column of this
          :func:`_orm.relationship` is ``b.a_id``.

          In normal cases, the :paramref:`_orm.relationship.foreign_keys`
          parameter is **not required.** :func:`_orm.relationship` will
          automatically determine which columns in the
          :paramref:`_orm.relationship.primaryjoin` condition are to be
          considered "foreign key" columns based on those
          :class:`_schema.Column` objects that specify
          :class:`_schema.ForeignKey`,
          or are otherwise listed as referencing columns in a
          :class:`_schema.ForeignKeyConstraint` construct.
          :paramref:`_orm.relationship.foreign_keys` is only needed when:

            1. There is more than one way to construct a join from the local
               table to the remote table, as there are multiple foreign key
               references present.  Setting ``foreign_keys`` will limit the
               :func:`_orm.relationship`
               to consider just those columns specified
               here as "foreign".

            2. The :class:`_schema.Table` being mapped does not actually have
               :class:`_schema.ForeignKey` or
               :class:`_schema.ForeignKeyConstraint`
               constructs present, often because the table
               was reflected from a database that does not support foreign key
               reflection (MySQL MyISAM).

            3. The :paramref:`_orm.relationship.primaryjoin`
               argument is used to
               construct a non-standard join condition, which makes use of
               columns or expressions that do not normally refer to their
               "parent" column, such as a join condition expressed by a
               complex comparison using a SQL function.

          The :func:`_orm.relationship` construct will raise informative
          error messages that suggest the use of the
          :paramref:`_orm.relationship.foreign_keys` parameter when
          presented with an ambiguous condition.   In typical cases,
          if :func:`_orm.relationship` doesn't raise any exceptions, the
          :paramref:`_orm.relationship.foreign_keys` parameter is usually
          not needed.

          :paramref:`_orm.relationship.foreign_keys` may also be passed as a
          callable function which is evaluated at mapper initialization time,
          and may be passed as a Python-evaluable string when using
          Declarative.

          .. warning:: When passed as a Python-evaluable string, the
             argument is interpreted using Python's ``eval()`` function.
             **DO NOT PASS UNTRUSTED INPUT TO THIS STRING**.
             See :ref:`declarative_relationship_eval` for details on
             declarative evaluation of :func:`_orm.relationship` arguments.

          .. seealso::

            :ref:`relationship_foreign_keys`

            :ref:`relationship_custom_foreign`

            :func:`.foreign` - allows direct annotation of the "foreign"
            columns within a :paramref:`_orm.relationship.primaryjoin`
            condition.

        :param info: Optional data dictionary which will be populated into the
            :attr:`.MapperProperty.info` attribute of this object.

        :param innerjoin=False:
          When ``True``, joined eager loads will use an inner join to join
          against related tables instead of an outer join.  The purpose
          of this option is generally one of performance, as inner joins
          generally perform better than outer joins.

          This flag can be set to ``True`` when the relationship references an
          object via many-to-one using local foreign keys that are not
          nullable, or when the reference is one-to-one or a collection that
          is guaranteed to have one or at least one entry.

          The option supports the same "nested" and "unnested" options as
          that of :paramref:`_orm.joinedload.innerjoin`.  See that flag
          for details on nested / unnested behaviors.

          .. seealso::

            :paramref:`_orm.joinedload.innerjoin` - the option as specified by
            loader option, including detail on nesting behavior.

            :ref:`what_kind_of_loading` - Discussion of some details of
            various loader options.


        :param join_depth:
          When non-``None``, an integer value indicating how many levels
          deep "eager" loaders should join on a self-referring or cyclical
          relationship.  The number counts how many times the same Mapper
          shall be present in the loading condition along a particular join
          branch.  When left at its default of ``None``, eager loaders
          will stop chaining when they encounter a the same target mapper
          which is already higher up in the chain.  This option applies
          both to joined- and subquery- eager loaders.

          .. seealso::

            :ref:`self_referential_eager_loading` - Introductory documentation
            and examples.

        :param lazy='select': specifies
          How the related items should be loaded.  Default value is
          ``select``.  Values include:

          * ``select`` - items should be loaded lazily when the property is
            first accessed, using a separate SELECT statement, or identity map
            fetch for simple many-to-one references.

          * ``immediate`` - items should be loaded as the parents are loaded,
            using a separate SELECT statement, or identity map fetch for
            simple many-to-one references.

          * ``joined`` - items should be loaded "eagerly" in the same query as
            that of the parent, using a JOIN or LEFT OUTER JOIN.  Whether
            the join is "outer" or not is determined by the
            :paramref:`_orm.relationship.innerjoin` parameter.

          * ``subquery`` - items should be loaded "eagerly" as the parents are
            loaded, using one additional SQL statement, which issues a JOIN to
            a subquery of the original statement, for each collection
            requested.

          * ``selectin`` - items should be loaded "eagerly" as the parents
            are loaded, using one or more additional SQL statements, which
            issues a JOIN to the immediate parent object, specifying primary
            key identifiers using an IN clause.

            .. versionadded:: 1.2

          * ``noload`` - no loading should occur at any time.  This is to
            support "write-only" attributes, or attributes which are
            populated in some manner specific to the application.

          * ``raise`` - lazy loading is disallowed; accessing
            the attribute, if its value were not already loaded via eager
            loading, will raise an :exc:`~sqlalchemy.exc.InvalidRequestError`.
            This strategy can be used when objects are to be detached from
            their attached :class:`.Session` after they are loaded.

            .. versionadded:: 1.1

          * ``raise_on_sql`` - lazy loading that emits SQL is disallowed;
            accessing the attribute, if its value were not already loaded via
            eager loading, will raise an
            :exc:`~sqlalchemy.exc.InvalidRequestError`, **if the lazy load
            needs to emit SQL**.  If the lazy load can pull the related value
            from the identity map or determine that it should be None, the
            value is loaded.  This strategy can be used when objects will
            remain associated with the attached :class:`.Session`, however
            additional SELECT statements should be blocked.

            .. versionadded:: 1.1

          * ``dynamic`` - the attribute will return a pre-configured
            :class:`_query.Query` object for all read
            operations, onto which further filtering operations can be
            applied before iterating the results.  See
            the section :ref:`dynamic_relationship` for more details.

          * True - a synonym for 'select'

          * False - a synonym for 'joined'

          * None - a synonym for 'noload'

          .. seealso::

            :doc:`/orm/loading_relationships` - Full documentation on
            relationship loader configuration.

            :ref:`dynamic_relationship` - detail on the ``dynamic`` option.

            :ref:`collections_noload_raiseload` - notes on "noload" and "raise"

        :param load_on_pending=False:
          Indicates loading behavior for transient or pending parent objects.

          When set to ``True``, causes the lazy-loader to
          issue a query for a parent object that is not persistent, meaning it
          has never been flushed.  This may take effect for a pending object
          when autoflush is disabled, or for a transient object that has been
          "attached" to a :class:`.Session` but is not part of its pending
          collection.

          The :paramref:`_orm.relationship.load_on_pending`
          flag does not improve
          behavior when the ORM is used normally - object references should be
          constructed at the object level, not at the foreign key level, so
          that they are present in an ordinary way before a flush proceeds.
          This flag is not not intended for general use.

          .. seealso::

              :meth:`.Session.enable_relationship_loading` - this method
              establishes "load on pending" behavior for the whole object, and
              also allows loading on objects that remain transient or
              detached.

        :param order_by:
          Indicates the ordering that should be applied when loading these
          items.  :paramref:`_orm.relationship.order_by`
          is expected to refer to
          one of the :class:`_schema.Column`
          objects to which the target class is
          mapped, or the attribute itself bound to the target class which
          refers to the column.

          :paramref:`_orm.relationship.order_by`
          may also be passed as a callable
          function which is evaluated at mapper initialization time, and may
          be passed as a Python-evaluable string when using Declarative.

          .. warning:: When passed as a Python-evaluable string, the
             argument is interpreted using Python's ``eval()`` function.
             **DO NOT PASS UNTRUSTED INPUT TO THIS STRING**.
             See :ref:`declarative_relationship_eval` for details on
             declarative evaluation of :func:`_orm.relationship` arguments.

        :param passive_deletes=False:
           Indicates loading behavior during delete operations.

           A value of True indicates that unloaded child items should not
           be loaded during a delete operation on the parent.  Normally,
           when a parent item is deleted, all child items are loaded so
           that they can either be marked as deleted, or have their
           foreign key to the parent set to NULL.  Marking this flag as
           True usually implies an ON DELETE <CASCADE|SET NULL> rule is in
           place which will handle updating/deleting child rows on the
           database side.

           Additionally, setting the flag to the string value 'all' will
           disable the "nulling out" of the child foreign keys, when the parent
           object is deleted and there is no delete or delete-orphan cascade
           enabled.  This is typically used when a triggering or error raise
           scenario is in place on the database side.  Note that the foreign
           key attributes on in-session child objects will not be changed after
           a flush occurs so this is a very special use-case setting.
           Additionally, the "nulling out" will still occur if the child
           object is de-associated with the parent.

           .. seealso::

                :ref:`passive_deletes` - Introductory documentation
                and examples.

        :param passive_updates=True:
          Indicates the persistence behavior to take when a referenced
          primary key value changes in place, indicating that the referencing
          foreign key columns will also need their value changed.

          When True, it is assumed that ``ON UPDATE CASCADE`` is configured on
          the foreign key in the database, and that the database will
          handle propagation of an UPDATE from a source column to
          dependent rows.  When False, the SQLAlchemy
          :func:`_orm.relationship`
          construct will attempt to emit its own UPDATE statements to
          modify related targets.  However note that SQLAlchemy **cannot**
          emit an UPDATE for more than one level of cascade.  Also,
          setting this flag to False is not compatible in the case where
          the database is in fact enforcing referential integrity, unless
          those constraints are explicitly "deferred", if the target backend
          supports it.

          It is highly advised that an application which is employing
          mutable primary keys keeps ``passive_updates`` set to True,
          and instead uses the referential integrity features of the database
          itself in order to handle the change efficiently and fully.

          .. seealso::

              :ref:`passive_updates` - Introductory documentation and
              examples.

              :paramref:`.mapper.passive_updates` - a similar flag which
              takes effect for joined-table inheritance mappings.

        :param post_update:
          This indicates that the relationship should be handled by a
          second UPDATE statement after an INSERT or before a
          DELETE. Currently, it also will issue an UPDATE after the
          instance was UPDATEd as well, although this technically should
          be improved. This flag is used to handle saving bi-directional
          dependencies between two individual rows (i.e. each row
          references the other), where it would otherwise be impossible to
          INSERT or DELETE both rows fully since one row exists before the
          other. Use this flag when a particular mapping arrangement will
          incur two rows that are dependent on each other, such as a table
          that has a one-to-many relationship to a set of child rows, and
          also has a column that references a single child row within that
          list (i.e. both tables contain a foreign key to each other). If
          a flush operation returns an error that a "cyclical
          dependency" was detected, this is a cue that you might want to
          use :paramref:`_orm.relationship.post_update` to "break" the cycle.

          .. seealso::

              :ref:`post_update` - Introductory documentation and examples.

        :param primaryjoin:
          A SQL expression that will be used as the primary
          join of the child object against the parent object, or in a
          many-to-many relationship the join of the parent object to the
          association table. By default, this value is computed based on the
          foreign key relationships of the parent and child tables (or
          association table).

          :paramref:`_orm.relationship.primaryjoin` may also be passed as a
          callable function which is evaluated at mapper initialization time,
          and may be passed as a Python-evaluable string when using
          Declarative.

          .. warning:: When passed as a Python-evaluable string, the
             argument is interpreted using Python's ``eval()`` function.
             **DO NOT PASS UNTRUSTED INPUT TO THIS STRING**.
             See :ref:`declarative_relationship_eval` for details on
             declarative evaluation of :func:`_orm.relationship` arguments.

          .. seealso::

              :ref:`relationship_primaryjoin`

        :param remote_side:
          Used for self-referential relationships, indicates the column or
          list of columns that form the "remote side" of the relationship.

          :paramref:`_orm.relationship.remote_side` may also be passed as a
          callable function which is evaluated at mapper initialization time,
          and may be passed as a Python-evaluable string when using
          Declarative.

          .. warning:: When passed as a Python-evaluable string, the
             argument is interpreted using Python's ``eval()`` function.
             **DO NOT PASS UNTRUSTED INPUT TO THIS STRING**.
             See :ref:`declarative_relationship_eval` for details on
             declarative evaluation of :func:`_orm.relationship` arguments.

          .. seealso::

            :ref:`self_referential` - in-depth explanation of how
            :paramref:`_orm.relationship.remote_side`
            is used to configure self-referential relationships.

            :func:`.remote` - an annotation function that accomplishes the
            same purpose as :paramref:`_orm.relationship.remote_side`,
            typically
            when a custom :paramref:`_orm.relationship.primaryjoin` condition
            is used.

        :param query_class:
          A :class:`_query.Query`
          subclass that will be used as the base of the
          "appender query" returned by a "dynamic" relationship, that
          is, a relationship that specifies ``lazy="dynamic"`` or was
          otherwise constructed using the :func:`_orm.dynamic_loader`
          function.

          .. seealso::

            :ref:`dynamic_relationship` - Introduction to "dynamic"
            relationship loaders.

        :param secondaryjoin:
          A SQL expression that will be used as the join of
          an association table to the child object. By default, this value is
          computed based on the foreign key relationships of the association
          and child tables.

          :paramref:`_orm.relationship.secondaryjoin` may also be passed as a
          callable function which is evaluated at mapper initialization time,
          and may be passed as a Python-evaluable string when using
          Declarative.

          .. warning:: When passed as a Python-evaluable string, the
             argument is interpreted using Python's ``eval()`` function.
             **DO NOT PASS UNTRUSTED INPUT TO THIS STRING**.
             See :ref:`declarative_relationship_eval` for details on
             declarative evaluation of :func:`_orm.relationship` arguments.

          .. seealso::

              :ref:`relationship_primaryjoin`

        :param single_parent:
          When True, installs a validator which will prevent objects
          from being associated with more than one parent at a time.
          This is used for many-to-one or many-to-many relationships that
          should be treated either as one-to-one or one-to-many.  Its usage
          is optional, except for :func:`_orm.relationship` constructs which
          are many-to-one or many-to-many and also
          specify the ``delete-orphan`` cascade option.  The
          :func:`_orm.relationship` construct itself will raise an error
          instructing when this option is required.

          .. seealso::

            :ref:`unitofwork_cascades` - includes detail on when the
            :paramref:`_orm.relationship.single_parent`
            flag may be appropriate.

        :param uselist:
          A boolean that indicates if this property should be loaded as a
          list or a scalar. In most cases, this value is determined
          automatically by :func:`_orm.relationship` at mapper configuration
          time, based on the type and direction
          of the relationship - one to many forms a list, many to one
          forms a scalar, many to many is a list. If a scalar is desired
          where normally a list would be present, such as a bi-directional
          one-to-one relationship, set :paramref:`_orm.relationship.uselist`
          to
          False.

          The :paramref:`_orm.relationship.uselist`
          flag is also available on an
          existing :func:`_orm.relationship`
          construct as a read-only attribute,
          which can be used to determine if this :func:`_orm.relationship`
          deals
          with collections or scalar attributes::

              >>> User.addresses.property.uselist
              True

          .. seealso::

              :ref:`relationships_one_to_one` - Introduction to the "one to
              one" relationship pattern, which is typically when the
              :paramref:`_orm.relationship.uselist` flag is needed.

        :param viewonly=False:
          When set to ``True``, the relationship is used only for loading
          objects, and not for any persistence operation.  A
          :func:`_orm.relationship` which specifies
          :paramref:`_orm.relationship.viewonly` can work
          with a wider range of SQL operations within the
          :paramref:`_orm.relationship.primaryjoin` condition, including
          operations that feature the use of a variety of comparison operators
          as well as SQL functions such as :func:`_expression.cast`.  The
          :paramref:`_orm.relationship.viewonly`
          flag is also of general use when defining any kind of
          :func:`_orm.relationship` that doesn't represent
          the full set of related objects, to prevent modifications of the
          collection from resulting in persistence operations.

          When using the :paramref:`_orm.relationship.viewonly` flag in
          conjunction with backrefs, the
          :paramref:`_orm.relationship.sync_backref` should be set to False;
          this indicates that the backref should not actually populate this
          relationship with data when changes occur on the other side; as this
          is a viewonly relationship, it cannot accommodate changes in state
          correctly as these will not be persisted.

          .. versionadded:: 1.3.17 - the
             :paramref:`_orm.relationship.sync_backref`
             flag set to False is required when using viewonly in conjunction
             with backrefs. A warning is emitted when this flag is not set.

          .. seealso::

            :paramref:`_orm.relationship.sync_backref`

        :param sync_backref:
          A boolean that enables the events used to synchronize the in-Python
          attributes when this relationship is target of either
          :paramref:`_orm.relationship.backref` or
          :paramref:`_orm.relationship.back_populates`.

          Defaults to ``None``, which indicates that an automatic value should
          be selected based on the value of the
          :paramref:`_orm.relationship.viewonly` flag.  When left at its
          default, changes in state for writable relationships will be
          back-populated normally.  For viewonly relationships, a warning is
          emitted unless the flag is set to ``False``.

          .. versionadded:: 1.3.17

          .. seealso::

            :paramref:`_orm.relationship.viewonly`

        :param omit_join:
          Allows manual control over the "selectin" automatic join
          optimization.  Set to ``False`` to disable the "omit join" feature
          added in SQLAlchemy 1.3; or leave as ``None`` to leave automatic
          optimization in place.

          .. note:: This flag may only be set to ``False``.   It is not
             necessary to set it to ``True`` as the "omit_join" optimization is
             automatically detected; if it is not detected, then the
             optimization is not supported.

             .. versionchanged:: 1.3.11  setting ``omit_join`` to True will now
                emit a warning as this was not the intended use of this flag.

          .. versionadded:: 1.3


        Nr3z-sync_backref and viewonly cannot both be Truez�setting 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.�lazyFzsave-update, merge)�warnzCbackref and back_populates keyword arguments are mutually exclusive)2�superr1�__init__�uselist�argument�	secondary�primaryjoin�
secondaryjoin�post_update�	direction�viewonly� _warn_for_persistence_only_flags�sa_exc�
ArgumentError�sync_backrefr<�
single_parent�_user_defined_foreign_keys�collection_classr4r8r5�remote_sider6�query_class�	innerjoin�distinct_target_key�docr7�
join_depthrr=�	omit_join�local_remote_pairsr9�bake_queries�load_on_pending�
Comparator�comparator_factory�
comparator�set_creation_order�info�strategy_key�set�_reverse_property�cascade�_set_cascade�order_by�back_populates�backref)$�selfrArBrCrD�foreign_keysr@rcrerdrErar9rGr<rNr4r5rOr6rTrZrLrQrRrSr7r8rXrW�_local_remote_pairsrPr]rUrK�	__class__s$                                   �r+r?zRelationshipProperty.__init__usm���p	�"�D�)�)�2�2�4�4�4���� ��
�"���&���*���&������ ��
��	��1�1� /� /�"3�-�!1�
2�
�
�
��	��	��&�?���
�)�����	�*���*6��'� 0���.��� 0���.���&���!2���&���"���#6�� ����,���$����	��I��
�
�
�#���"5���"���(���.����A�"6�"A�	
���1�1�$��=�=������%�%�%����D�I�$�d�i�0�2���!$������%���"�D�L�L����2���?�?�?� ��
�,�����	#��
��*�-���� �D�L�L�L�"�D�L�L�Lr,c��|���D].\}}||j|krtjd|�d����/dS)NzSetting 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_onlyrr=)rf�kw�k�vs    r+rHz5RelationshipProperty._warn_for_persistence_only_flags!sa���H�H�J�J�	�	�D�A�q��D�*�1�-�-�-��	�	�
/0�a�a�	2�����	�	r,c�~�tj|j|j|�||��||j���dS)N)r[�parententityrS)r�register_descriptor�class_�keyrZrS�rfrs  r+�instrument_classz%RelationshipProperty.instrument_class3sK���&��M��H��.�.�t�V�<�<����	
�	
�	
�	
�	
�	
r,c���eZdZdZdZ	dd�Zd�Zejd���Z	ejd���Z
ejd���Zd�Zd	�Z
d
�Zd�ZdZd�Zdd
�Zdd�Zdd�Zd�Zd�Zd�Zejd���ZdS)�RelationshipProperty.Comparatora�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`

        Nc�F�||_||_||_|r	||_dSdS)z�Construction of :class:`.RelationshipProperty.Comparator`
            is internal to the ORM's attribute mechanics.

            N)�prop�
_parententity�_adapt_to_entity�_of_type)rfrz�parentmapper�adapt_to_entity�of_types     r+r?z(RelationshipProperty.Comparator.__init__Ss8���D�I�!-�D��$3�D�!��
(� '��
�
�
�
(�
(r,c�R�|�|j|j||j���S)N�rr�)ri�propertyr{r})rfrs  r+rz/RelationshipProperty.Comparator.adapt_to_entity`s0���>�>��
��"� /��
�	"���
r,c��|jjS)a+The target entity referred to by this
            :class:`.RelationshipProperty.Comparator`.

            This is either a :class:`_orm.Mapper` or :class:`.AliasedInsp`
            object.

            This is the "target" or "remote" side of the
            :func:`_orm.relationship`.

            )r��entity�rfs r+r�z&RelationshipProperty.Comparator.entityhs���=�'�'r,c��|jjS)z�The target :class:`_orm.Mapper` referred to by this
            :class:`.RelationshipProperty.Comparator`.

            This is the "target" or "remote" side of the
            :func:`_orm.relationship`.

            )r�rr�s r+rz&RelationshipProperty.Comparator.mappervs���=�'�'r,c��|jjS�N)r��parentr�s r+r{z-RelationshipProperty.Comparator._parententity�s
���=�'�'r,c�J�|jr|jjS|jjjSr�)r|�
selectabler�r��_with_polymorphic_selectabler�s r+�_source_selectablez2RelationshipProperty.Comparator._source_selectable�s(���$�
I��,�7�7��}�+�H�Hr,c���|���}|jrt|j��j}nd}|j�|d|d���\}}}}}}|�||zS|S)NT)�source_selectable�source_polymorphic�of_type_mapper�alias_secondary)r�r}rrr��
_create_joins)	rf�
adapt_fromr��pj�sj�source�destrB�target_adapters	         r+�__clause_element__z2RelationshipProperty.Comparator.__clause_element__�s����0�0�2�2�J��}�
&�!(���!7�!7�!>���!%���
�+�+�",�#'�-� $�	,���
��������~��B�w���	r,c�\�t�|j|j|j|���S)z�Redefine this object in terms of a polymorphic subclass.

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

            r�)r1rYr�r{r|)rf�clss  r+r�z'RelationshipProperty.Comparator.of_type�s5��(�2�2��
��"� $� 5��	3���
r,c� �td���)z�Produce 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�rf�others  r+�in_z#RelationshipProperty.Comparator.in_�s��
&�1���
r,c��t|tjtjf��r]|jjttfvr|�	��St|j�d|j�����S|jj
rtjd���t|j�||j�����S)a�Implement the ``==`` operator.

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

              MyClass.some_prop == <some object>

            this will typically produce a
            clause such as::

              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:`~.RelationshipProperty.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:`~.RelationshipProperty.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.)�
isinstancer�NoneTyper�Nullr�rFrr
�_criterion_existsr�_optimized_compare�adapterr@rI�InvalidRequestErrorr�s  r+�__eq__z&RelationshipProperty.Comparator.__eq__�s���J�%�$�-���!A�B�B�
��=�*�y�*�.E�E�E� �2�2�4�4�4�4�(��
�8�8� �t�|�9������
��&�

��0�=����
%��M�4�4��D�L�5�����r,c��t|dd��r_t|j��}|j|j|j}}}|jjr|s|���}|j	}|�
|�||z}n|}nd}d}|j
r|���}nd}|j�d||���\}	}
}}}
}|D]5}t|jjj
|��||k}|�|}�0||z}�6|
�t|	��|
z}nt|	|jj���}|�|r|s|�|��}|�|�ddi��}|t$j�|��z}|
�/t%jdg|||
g����||
��}n+t%jdg||����|��}|S)	Nr}FT)�dest_polymorphic�dest_selectabler�)�exclude�no_replacement_traverser)�from_obj)�getattrrr}rr��is_aliased_classr��_is_self_referential�alias�_single_table_criterionr�r�r�rsrrO�traverse�	_annotater�True_�_ifnone�exists�correlate_except)rf�	criterion�kwargsr]�
target_mapper�
to_selectabler��single_critr�r�r�r�r�rBr�rn�crit�j�exs                   r+r�z1RelationshipProperty.Comparator._criterion_exists�sU���t�Z��.�.�
%��t�}�-�-���K��O��)�/?�}�
�
�=�5�:�>N�:�$1�$7�$7�$9�$9�M�+�C���*� �,�$/�)�$;�	�	�$/�	��#(� � $�
��|�
)�$(�$;�$;�$=�$=�!�!�$(�!��
�+�+�!%� -�"3�,���
��������
1�
1���t�}�3�:�A�>�>�&��)�K���$� $�I�I� )�D� 0�I�I�
�~�!�"�%�%��*���!�"�d�m�.G�H�H�H���%�"�&�(�&�
+�3�3�I�>�>�	��$�%�/�/�.��5���	��s�y�(�(��3�3�3�D��$��Z��C���y�(9����"�"�4��3�3����Z���T�D�9�9�9�J�J������Ir,c�^�|jjstjd���|j|fi|��S)aqProduce 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::

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

            Because :meth:`~.RelationshipProperty.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:`~.RelationshipProperty.Comparator.any` is particularly
            useful for testing for empty collections::

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

            will produce::

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

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

            z9'any()' not implemented for scalar attributes. Use has().�r�r@rIr�r��rfr�r�s   r+�anyz#RelationshipProperty.Comparator.anyMsI��R�=�(�
��0�-����
*�4�)�)�>�>�v�>�>�>r,c�^�|jjrtjd���|j|fi|��S)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::

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

            Because :meth:`~.RelationshipProperty.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:`~.RelationshipProperty.Comparator.has` is only
            valid for scalar references, i.e. a :func:`_orm.relationship`
            that has ``uselist=False``.  For collection references,
            use :meth:`~.RelationshipProperty.Comparator.any`.

            z4'has()' not implemented for collections.  Use any().r�r�s   r+�hasz#RelationshipProperty.Comparator.has~sF��8�}�$�
��0�M����*�4�)�)�>�>�v�>�>�>r,c���|jjstjd���|j�||j���}|jj�|�|��|_|S)au	Return a simple expression that tests a collection for
            containment of a particular item.

            :meth:`~.RelationshipProperty.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::

                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:`~.RelationshipProperty.Comparator.contains` is
            very useful when used with simple one-to-many
            operations.

            For many-to-many operations, the behavior of
            :meth:`~.RelationshipProperty.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::

                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:`~.RelationshipProperty.Comparator.contains`
            will **not** work with many-to-many collections when
            used in queries that move beyond simple AND
            conjunctions, such as multiple
            :meth:`~.RelationshipProperty.Comparator.contains`
            expressions joined by OR. In such cases subqueries or
            explicit "outer joins" will need to be used instead.
            See :meth:`~.RelationshipProperty.Comparator.any` for
            a less-performant alternative using EXISTS, or refer
            to :meth:`_query.Query.outerjoin`
            as well as :ref:`ormtutorial_joins`
            for more details on constructing outer joins.

            z9'contains' not implemented for scalar attributes.  Use ==r�)	r�r@rIr�r�r�rD�'_Comparator__negated_contains_or_equals�negation_clause)rfr�r��clauses    r+�containsz(RelationshipProperty.Comparator.contains�s���r�=�(�
��0�*�����]�5�5��D�L�6���F��}�*�6�)-�)J�)J��*�*��&��Mr,c	�������jjtkrPtj|����fd���fd���jjr&t
j���fd��jjD���St
jd�t�jj
j�jj
�|����D���}��
|��S)Nc
���|j}tj|d�j��jj|||�����S)NT)�unique�	callable_)�dictr�	bindparamr��_get_attr_w_warn_on_noner)�x�state�col�dict_rfs    �r+�state_bindparamzURelationshipProperty.Comparator.__negated_contains_or_equals.<locals>.state_bindparam�sL���!�J�E��=��#�"&�-�"H�"H� �M�0�%���#�#����r,c�@���jr��|��S|Sr�)r��r�rfs �r+�adaptzKRelationshipProperty.Comparator.__negated_contains_or_equals.<locals>.adapt�s$����|�#�#�|�|�C�0�0�0�"�
r,c
���g|]H\}}tj�|����|���|��k�|��dk����ISr�)r�or_)�.0r��yr�r�r�s   ���r+�
<listcomp>zPRelationshipProperty.Comparator.__negated_contains_or_equals.<locals>.<listcomp>�su������!'��A� �G� %��a���#2�?�5�5��8�8�U�A�#F�#F�!G� %��a���D� 0�����r,c� �g|]\}}||k��S�r��r�r�r�s   r+r�zPRelationshipProperty.Comparator.__negated_contains_or_equals.<locals>.<listcomp>
s0�������A���F���r,)r�rFrr�instance_state�_use_getr�and_rV�zipr�primary_key�primary_key_from_instancer�)rfr�r�r�r�r�s`  @@@r+�__negated_contains_or_equalsz<RelationshipProperty.Comparator.__negated_contains_or_equals�s�������}�&�)�3�3�"�1�%�8�8�������#�#�#�#�#��=�)�
��8�������+/�-�*J�
���	�	�����"%��
�,�8��
�,�F�F�u�M�M�#�#�����I��*�*�9�5�5�5�5r,c��t|tjtjf��rX|jjtkr/t|j�	d|j
�����S|���S|jjrtjd���t|�|����S)a"Implement the ``!=`` operator.

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

              MyClass.some_prop != <some object>

            This will typically produce a clause such as::

              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:`~.RelationshipProperty.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:`~.RelationshipProperty.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.

            Nr�r�)r�rr�rr�r�rFrrr�r�r�r@rIr�r�r�s  r+�__ne__z&RelationshipProperty.Comparator.__ne__s���N�%�$�-���!A�B�B�
O��=�*�i�7�7�(���9�9� �t�|�:������� �1�1�3�3�3���&�
O��0�9����%�T�%F�%F�u�%M�%M�N�N�Nr,c�n�tjjrtj���|jSr�)�	mapperlib�Mapper�_new_mappers�_configure_allrzr�s r+r�z(RelationshipProperty.Comparator.propertyOs-����,�
2�� �/�/�1�1�1��9�r,)NNr�)�__name__�
__module__�__qualname__�__doc__r}r?rr�memoized_propertyr�rr{r�r�r�r��__hash__r�r�r�r�r�r�r�r�r�r,r+rYrx<s�������	�	�(��EI�	(�	(�	(�	(�	�	�	�
�	�	(�	(�
 �	�	(�
�	�	(�	(�
 �	�	(�
�	�	(�	(�
 �	�	(�	I�	I�	I�	�	�	�2	�	�	�
	�
	�
	���8	�8	�8	�tR	�R	�R	�R	�h/	?�/	?�/	?�/	?�b 	?� 	?� 	?� 	?�DG	�G	�G	�R*	6�*	6�*	6�X8	O�8	O�8	O�t
�	�	�	�
 �	�	�	�	r,rYc��|�J�d}|�"t|��}|jr|jj}|�|d||���S)NT)�value_is_parentr�r�)rr��_adapter�adapt_clauser�)rf�instancer��from_entityr��insps      r+�_with_parentz!RelationshipProperty._with_parentUsd���#�#�#����"��;�'�'�D��$�
:�#�}�9���&�&�� �%�+�	'�
�
�	
r,c�����	�
���R	t����n#tj$rd�YnwxYw��t�dd��stjd�z���|}����||���S|s�jj�jjc}�n�jj	�jj
c}�|r�j�
n�j�
tj�������	��	�
��fd�}�j�;|r9t#�j������|��}t)j|id|i��}|r||��}|S)N�is_instanceFz�Mapped 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).r�c�n��|j�vr*������|j��|_dSdSr�)�_identifying_keyr��callable)r��bind_to_colr�rrfr�s �����r+�visit_bindparamz@RelationshipProperty._optimized_compare.<locals>.visit_bindparam�sK����)�[�8�8�%)�%B�%B�����	� :�;�	&�&�	�"�"�"�9�8r,r�)rrI�NoInspectionAvailabler�rJ�_lazy_none_clause�_lazy_strategy�
_lazywhere�_bind_to_col�_rev_lazywhere�_rev_bind_to_colrr�r�
instance_dict�objrBrr�r�r�cloned_traverse)rfr�r�r�r��reverse_directionr�rrr�rs``      @@@r+r�z'RelationshipProperty._optimized_comparecs����������
���������/�
�
�
�����
�����}�G�E�=�%�$H�$H�}��*�.�15�	5����!0�/���=��)�)�!��*���
�!�		��#�.��#�0�
#�I�{�{��#�2��#�4�
#�I�{�
�	!��[�F�F��[�F��(������5�5��	�	�	�	�	�	�	�	�	��>�%�/�%�%�d�n�&:�&:�&<�&<�=�=�F�F����I��,��r�K��9�
�
�	��	0�$��Y�/�/�I��s��-�-c����������������j�������fd�}|S)aKCreate 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�����j�jx}}|tju}������jrtjntjtjz���}|tj	ur+|s(tjd��dt����d����n;|tj
ur+|s(tjd��dt����d����n|}|�tjd�z��|S)N��passivezCan'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 expiredz�Got 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))�_last_known_valuesrtr�NO_VALUE�_get_state_attr_by_column�
persistent�PASSIVE_OFF�PASSIVE_NO_FETCH�INIT_OK�	NEVER_SETrIr�r	�PASSIVE_NO_RESULTrr=)	�
last_known�	to_return�existing_is_available�
current_value�columnr�rrzr�s	    �����r+�_goz:RelationshipProperty._get_attr_w_warn_on_none.<locals>._go�sJ���%*�%=�d�h�%G�G�J��$.�j�6I�$I�!�#�<�<�����#�F�
�.�.��0�:�3E�E�
=���M��
� 4�4�4�,�� �4�4�"�6�6�9�U�#3�#3�#3�#3�5������*�">�>�>�,�� �4�4�&,�V�V�Y�u�-=�-=�-=�-=�?�����*�	�� ��	�4�7=�=�����r,)�get_property_by_column�_track_last_known_valuert)rfrr�r�r)r*rzs ```` @r+r�z-RelationshipProperty._get_attr_w_warn_on_none�sj�������V�,�,�V�4�4��
	�%�%�d�h�/�/�/�(	�(	�(	�(	�(	�(	�(	�(	�(	�T�
r,c��|s|jj|jj}}n|jj|jj}}t||��}|r||��}|Sr�)rrrrrr)rfrr�r�rs     r+rz&RelationshipProperty._lazy_none_clausesn�� �		��#�.��#�0�#�I�I��#�2��#�4�#�I�
,�I�{�C�C�	��	0�$��Y�/�/�I��r,c�T�t|jjj��dz|jzS)N�.)�strr�rsr�rtr�s r+�__str__zRelationshipProperty.__str__s$���4�;�%�.�/�/�#�5���@�@r,c	�.�|r|jD]}	||	f|vrdS�d|jvrdS|j|vrdS|j�rH|�|j���||��}
t
|
d��r|
j}
|r.|�|j���||��g}|
D]b}tj	|��}
tj
|��}d||
|f<|�|
||||���}|�|�|���c|s7tj
|||j��}|D]}|�|���dS|�|j���|||d���dS||j}|�Jtj	|��}
tj
|��}d||
|f<|�|
||||���}nd}|s|||j<dS|�|j���|||d��dS)N�merge�_sa_adapterT)�load�
_recursive�_resolve_conflict_mapF)�_adapt)r`�_cascadertr@�get_impl�get�hasattrr4rr�r�_merge�append�init_state_collection�append_without_eventr_)rf�session�source_state�source_dict�
dest_state�	dest_dictr5r6r7�r�	instances�	dest_list�current�
current_state�current_dictr�coll�cs                  r+r3zRelationshipProperty.merges����	��+�
�
�� �!�$�
�2�2��F�F�3��$�-�'�'��F��8�;�&�&��F��<�>	�$�-�-�d�h�7�7�;�;��k���I��y�-�0�0�
2�%�1�	��
I��#�#�D�H�-�-�1�1�*�i�H�H�H��I�$�
*�
*�� *� 9�'� B� B�
�)�7��@�@��48�
�M�4�0�1��n�n�!� ��)�*?�%�����?��$�$�S�)�)�)���	
�!�7��	�4�8����#�1�1�A��-�-�a�0�0�0�0�1�1��#�#�D�H�-�-�1�1��	�9�U�2������"�$�(�+�G��"� *� 9�'� B� B�
�)�7��@�@��48�
�M�4�0�1��n�n�!� ��)�*?�%��������
�&)�	�$�(�#�#�#��#�#�D�H�-�-�1�1��	�3������r,c��|j|j}|�|||���}|tjus|�gSt|d��r#d�|�||||���D��Stj|��|fgS)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
        rN�get_collectionc�:�g|]}tj|��|f��Sr�)rr�)r��os  r+r�z;RelationshipProperty._value_as_iterable.<locals>.<listcomp>s8�������*�1�-�-�q�1���r,)�manager�implr;rr$r<rOr�)rfr�r�rtrrSr�s       r+�_value_as_iterablez'RelationshipProperty._value_as_iterableqs����}�S�!�&���H�H�U�E�7�H�3�3���
�,�,�,��	��I�
�T�+�
,�
,�	7����,�,�U�E�1�g�,�N�N����
�
 �.�q�1�1�1�5�6�6r,c
#�K�|dks|jr
tj}ntj}|dkr,|j|jj�||��}n|�|||j|���}|dkod|j	v}|D]�\}	}
|	|vr�
|
��
tj
|
��}|r||	��r�/|r|	js�9|	jj}|�|jj
j��s-td|j�d|jj�d|
j�d	����|�|	��|
||	|fV���dS)
N�deletezsave-updaterzrefresh-expire�
delete-orphanzAttribute 'z' on class 'z"' doesn't handle objects of type '�')r4r�PASSIVE_NO_INITIALIZEr rRrtrS�get_all_pendingrTr9rr�isa�
class_manager�AssertionErrorr�rsri�add)
rf�type_r�r��visited_states�halt_onr�tuples�skip_pendingr�rMr�instance_mappers
             r+�cascade_iteratorz%RelationshipProperty.cascade_iterator�s������H���� 4�� �6�G�G� �,�G��M�!�!��]�4�8�,�1�A�A�%��O�O�F�F��,�,��u�d�h��-���F�

�%�%�N�/���*N�	�"(�	D�	D��N�A���/�/���y�
�&�4�Q�7�7�M��
�7�7�>�2�2�
���
�N�$6�
��,�4�;�O�"�&�&�t�{�'@�'G�H�H�
�$�n��x�x�x���!3�!3�!3�Q�[�[�[�B����
���~�.�.�.��_�n�m�C�C�C�C�C�?	D�	Dr,c��|jduS)NF)rKr�s r+�_effective_sync_backrefz,RelationshipProperty._effective_sync_backref�s��� ��-�-r,c��|jr"|jrtjd|�d|�d����|jr#|jdurt	jd|||f��dSdSdS)N�
Relationship z( cannot specify sync_backref=True since z includes viewonly=True.Fz�Setting backref / back_populates on relationship %s to refer to viewonly relationship %s should include sync_backref=False set on the %s relationship. )rGrKrIr�r�warn_limited)�rel_a�rel_bs  r+�_check_sync_backrefz(RelationshipProperty._check_sync_backref�s����>�	�e�0�	��,�,�-2�U�U�E�E�E�;���
��>�	�e�0��=�=���B���u�%�	
�
�
�
�
�	�	�=�=r,c
��|j�|d���}|�||��|�||��|j�|��|j�|��|j�|j��s%tjd|�d|�d|�d|j�����|j	ttfvr2|j	|j	kr$tj|�d|�d|j	�d	����dSdS)
NF)�_configure_mapperszreverse_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_propertyrmr`r^�
common_parentr�rIrJrFrr)rfrtr�s   r+�_add_reverse_propertyz*RelationshipProperty._add_reverse_property�s.����(�(���(�G�G��
	
� � ��u�-�-�-�	
� � ���-�-�-���"�"�5�)�)�)�
��#�#�D�)�)�)��|�)�)�$�+�6�6�	��&�&��3�3����e�e�e�T�[�[�2���
�
�N�y�)�4�4�4���%�/�1�1��&��5�5�$�$�$�����0���
�
5�4�1�1r,c���tj|j��r;t|jtt
jf��s|���}n|j}t|t��rtj|d���S	t|��}t|d��r|Sn#tj$rYnwxYwtjd|j
�dt	|���d����)zReturn the target mapped entity, which is an inspect() of the
        class or aliased class tha is referred towards.

        F��	configurer�relationship 'z2' expects a class or a mapper argument (received: �))rr
rAr��typer�r��class_mapperrr<rIr
rJrt)rfrAr�s   r+r�zRelationshipProperty.entity�s���=���'�'�	%�
��M�D�)�"2�3�1
�1
�	%��}�}���H�H��}�H��h��%�%�	E��)�(�e�D�D�D�D�	��X�&�&�F��v�x�(�(�
��
�
���+�	�	�	��D�	�����"�"��x�x�x��h�����
)�
�
�	
s�B*�*B<�;B<c��|jjS)z�Return the targeted :class:`_orm.Mapper` for this
        :class:`.RelationshipProperty`.

        This is a lazy-initializing static attribute.

        )r�rr�s r+rzRelationshipProperty.mappers���{�!�!r,c���|���|���|���|�|j��|���|���|j���tt|�����|�d��|_
dS)N))r<r:)�_check_conflicts�_process_dependent_arguments�_setup_join_conditions�_check_cascade_settingsr9�
_post_init�_generate_backref�_join_condition�"_warn_for_conflicting_sync_targetsr>r1�do_init�
_get_strategyr)rfris �r+r�zRelationshipProperty.do_inits�����������)�)�+�+�+��#�#�%�%�%��$�$�T�]�3�3�3���������� � � ���?�?�A�A�A�
�"�D�)�)�1�1�3�3�3�"�0�0�1F�G�G����r,c�(�dD]N}t||��}tj|��r(t|��st	|||�����OdD]E}t||��}|�1t	||tt
j||�������F|j�4t|j��r tj
d|j�d|�d����|jdur/|j�(d�tj|j��D��|_tj
d	�tj|j��D����|_tj
d
�tj|j��D����|_|jj|_dS)z�Convert incoming configuration arguments to their
        proper form.

        Callables are resolved, ORM annotations removed.

        )rcrCrDrBrMrO)rCrDNzsecondary 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�8�g|]}tj|d����S)rc�r�_only_column_elements�r�r�s  r+r�zERelationshipProperty._process_dependent_arguments.<locals>.<listcomp>Us5�������0��J�?�?���r,c3�@K�|]}tj|d��V��dS)rgNr�r�s  r+�	<genexpr>zDRelationshipProperty._process_dependent_arguments.<locals>.<genexpr>ZsC����:
�:
��
�,�Q��?�?�:
�:
�:
�:
�:
�:
r,c3�@K�|]}tj|d��V��dS)rONr�r�s  r+r�zDRelationshipProperty._process_dependent_arguments.<locals>.<genexpr>_sC����+
�+
��
�,�Q�
�>�>�+
�+
�+
�+
�+
�+
r,)r�rr
r�setattrrrr�rBrIrJrc�to_list�
column_set�
to_column_setrMrOr��persist_selectable�target)rf�attr�
attr_value�vals    r+r}z1RelationshipProperty._process_dependent_arguments&s���
�
	2�
	2�D�!��t�,�,�J��}�Z�(�(�
2�1A�*�1M�1M�
2���d�J�J�L�L�1�1�1��3�		�		�D��$��%�%�C������#�"�8��d�C�C��������>�%�*:�4�>�*J�*J�%��&�&�
*.�������	?���
��=��%�%�$�-�*C�����d�m�4�4����D�M�
+/�/�:
�:
��'��(G�H�H�:
�:
�:
�+
�+
��'�
 �?�+
�+
��'��(8�9�9�+
�+
�+
�
�
���
�k�4����r,c�4�tdid|jj�d|jj�d|jj�d|jj�d|j�d|j�d|j�d|jj�d	|j	j�d
|j
�d|j�d|j�d
|j
�d|�d|j�d|j��x|_}|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_dS)N�parent_persist_selectable�child_persist_selectable�parent_local_selectable�child_local_selectablerCrBrD�parent_equivalents�child_equivalents�consider_as_foreign_keysrVrO�self_referentialrz�support_sync�can_be_synced_fnr�)�
JoinConditionr�r�r��local_tablerCrBrD�_equivalent_columnsrrMrVrOr�rG�_columns_are_mappedr�rF�remote_columns�
local_columns�synchronize_pairs�foreign_key_columns�_calculated_foreign_keys�secondary_synchronize_pairs)rf�jcs  r+r~z+RelationshipProperty._setup_join_conditionsfs���$1�%
�%
�%
�&*�k�&D�&D�%
�%)�[�%C�%C�%
�%)�K�$;�$;�%
�$(�;�#:�#:�	%
�
�(�(�%
��n�n�
%
��,�,�%
� $�{�>�>�%
�#�k�=�=�%
�&*�%D�%D�%
� $�6�6�%
��(�(�%
�"�6�6�%
���%
�"�]�*�*�%
� "�5�5�!%
�	
���r�$�>����-�������"$�"7����,����-���!#�!5���(*�(>��%�+-�+I��(�(�(r,c	��|jjrytj|jjd����|j��sCtjd|j�d|jjj	�d|jjj	�d����dSdS)zOTest that this relationship is legal, warn about
        inheritance conflicts.Frtz)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�ryrs�has_propertyrtrIrJr�r�s r+r|z%RelationshipProperty._check_conflicts�s����;�"�	�9�+A��K��%�,
�,
�,
�
�,�t�x�
 �
 �	��&�&��H�H�H��K�&�/�/�/��K�&�/�/�/�	���
�	�	�	�	r,c��|jS)z\Return the current cascade setting for this
        :class:`.RelationshipProperty`.
        )r9r�s r+razRelationshipProperty.cascade�s��
�}�r,c�0�|�|��dSr�)rb�rfras  r+razRelationshipProperty.cascade�s�����'�"�"�"�"�"r,c�t�t|��}|rl|jret|���tj��}|r7tjdd�t|����z��d|j	vr|�
|��||_|jr||j_
dSdS)Na"Cascade settings "%s" should not be combined with a viewonly=True relationship.   This configuration will raise an error in version 1.4.  Note that in versions prior to 1.4, these cascade settings may still produce a mutating effect even though this relationship is marked as viewonly=True.�, r)rrGr_�
difference�_viewonly_cascadesrr=�join�sorted�__dict__rr9�_dependency_processorra)rfrar=�non_viewonlys    r+rbz!RelationshipProperty._set_cascade�s��� ��)�)���	�D�M�	��w�<�<�2�2��1���L��
��	�%�)-�	�	�&��2F�2F�(G�(G�
I�����t�}�$�$��(�(��1�1�1���
��%�	9�18�D�&�.�.�.�	9�	9r,c���|jro|jsh|jtus|jturLtjd||jturdnd|jjj	|j
jj	d�zd����|jdkrd|vsd	|vrtjd
|z���|jrD|j
���j
�|j|jjf��dSdS)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 referred towards 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.zmany-to-onezmany-to-many)�relrF�clsname�
relatedcls�bbf0)�code�allrVrWz^On %s, can't set passive_deletes='all' in conjunction with 'delete' or 'delete-orphan' cascade)�
delete_orphanrLrFr
rrIrJr�rsr�rr4�primary_mapper�_delete_orphansr>rtr�s  r+rz,RelationshipProperty._check_cascade_settings�s9���!�	��&�	���:�-�-���9�1L�1L��&�/� ��~��2�2�"/��'�#�{�1�:�"&�+�"4�"=�
���*�-���
�2��5�(�(�����?�g�#=�#=��&�;�=A�B���
�
� �	��K�&�&�(�(�8�?�?���4�;�-�.�
�
�
�
�
�	�	r,c�F�|j|jvo|j|j|uS)zaReturn True if this property will persist values on behalf
        of the given mapper.

        )rt�
relationshipsrus  r+�
_persists_forz"RelationshipProperty._persists_for�s-��
�H��,�,�
7��$�T�X�.�$�6�	
r,c���|D]o}|j� |jj�|��r�)|jjj�|��s"|jj�|��sdS�pdS)z�Return True if all columns in the given collection are
        mapped by the tables referenced by this :class:`.Relationship`.

        NFT)rBrM�contains_columnr�r�r�)rf�colsrMs   r+r�z(RelationshipProperty._columns_are_mapped�s���
�		�		�A���*��N�$�4�4�Q�7�7�+���;�1�3�C�C����
��k�m�3�3�A�6�6�
��u�u���tr,c
��|jjrdS|j��A|j�s9t	|jt
j��r
|ji}}n
|j\}}|j���}|j	sxt|������|j
��}|D]<}|�|��r%|j	stjd|�d|�d|�d�����=|j�A|�d|jj��}|�d|jj��}nL|�d|jj��}|�dd��}|rtjd���|�d	|j��}|j���}	|�d
|j��|�d|j��|�d|j��|�d
|j��||_t=|	|j||f||jd�|��}
|� ||
��|jr|�!|j��dSdS)zlInterpret the 'backref' instruction to create a
        :func:`_orm.relationship` complementary to this one.NzError creating backref 'z' on relationship 'z+': property of that name exists on mapper 'rXrCrDzOCan't assign 'secondaryjoin' on a backref against a non-secondary relationship.rgrGrEr5rK)rgrd)"r�r�rerdr�r�string_typesrr��concreter_�iterate_to_root�union�self_and_descendantsr�rIrJrB�popr��secondaryjoin_minus_local�primaryjoin_minus_local�primaryjoin_reverse_remoter�rM�
setdefaultrGrEr5rKr1rt�_configure_propertyrr)rf�backref_keyr�r�check�mr�r�rgr�r2s           r+r�z&RelationshipProperty._generate_backref		s����;�"�	��F��<�#�D�,?�#��$�,��(9�:�:�
3�&*�l�B�V���&*�l�#��V��[�/�/�1�1�F��?�
��F�2�2�4�4�5�5�;�;��/�������A��~�~�k�2�2��1�:��$�2�2� +�{�{�D�D�D�!�!�!�5������~�)��Z�Z�!��(�B�����Z�Z�#��(�@�����
�Z�Z�!��(�C�����Z�Z���6�6���� �4�@����
"�:�:��� ?���L��[�/�/�1�1�F����j�$�-�8�8�8����m�T�-=�>�>�>����/��1E�F�F�F����n�d�.?�@�@�@�"-�D��/������	�
*�#�x�
�����L�
�&�&�{�L�A�A�A���	<��&�&�t�':�;�;�;�;�;�	<�	<r,c��|j�|jtu|_|js&tj�|��|_dSdSr�)r@rFrrGr�DependencyProcessor�from_relationshipr�r�s r+r�zRelationshipProperty._post_initV	sS���<���>��:�D�L��}�	��.�@�@��0�0�
�&�&�&�	�	r,c��|j}|jS)zPmemoize the 'use_get' attribute of this RelationshipLoader's
        lazyloader.)r�use_get)rf�strategys  r+r�zRelationshipProperty._use_get^	s��
�&����r,c�@�|j�|j��Sr�)rrqr�r�s r+r�z)RelationshipProperty._is_self_referentialf	s���{�(�(���5�5�5r,c���d}|r	|j�d}|�|r|jjr|jj}|�<|jj}|r|jjrd}|jr|�|���}d}n||jjus|jjrd}|p|j}|j	}	|p|duo||jjup|j
}|j�||||	��\}
}}}
}|�|jj
}|�|jj
}|
|||||
fS)NFT)rBr��with_polymorphicr�r�r�rr�r�r��_is_from_containerr��join_targetsr�)rfr�r�r�r�r�r��aliased�dest_mapperr�rCrDrBr�s              r+r�z"RelationshipProperty._create_joinsj	sx�����	�t�~�9��G��$�!�
M�d�k�&B�
M�$(�K�$L�!��"�"�k�4�O��
�D�K�$@�
����(�
�->�-F�"1�"7�"7�"9�"9������4�;�#K�K�K��{�+�
L��G�$�3����!�9���
��T�)�
�!��{�?�@�8�$�7�	�
� �-�-�����
�
�
	
�������$� $�� 7���"�"�k�5�O�������

�	
r,)TN)FNT)FNr�)T)FNFNNF)1r�r�r�r��strategy_wildcard_keyr�rlr�r�deprecated_paramsr?rHrvr
rYrr�r�rr1r3rr rTrer�rg�staticmethodrmrrr�r�rr�r}r~r|ra�setterrbrr�r�r�r�r�r�r��
__classcell__)ris@r+r1r1[s�������	�	�+�������������!���T��
����������������
��)�*;�<�)�*;�<��+�,?�@����� ��(�)9�:�*�+=�>��� ��
���Ga#�a#�a#�a#�a#���a#�F���$
�
�
�W�W�W�W�W�^�W�W�W�r
�
�
�
�"���B�B�B�B�H\�\�\�|����$A�A�A�U�U�U�p*4�)?�7�7�7�7�,<@�6D�6D�6D�6D�p�.�.��X�.�����\�� � � �D
��
�
���
�:
��"�"���"�	H�	H�	H�	H�	H�>5�>5�>5�@J�J�J�:���(����X��
�^�#�#��^�#�9�9�9�9�>*�*�*�X	
�	
�	
����"K<�K<�K<�Z���
�� � ��� �
��6�6���6�
!������A
�A
�A
�A
�A
�A
�A
�A
r,r1c�4�����fd��|��|��}d�|S)Nc���t|tj��r'|�������}|�����|S)N)�clone)r�r�ColumnClauser��copy�_copy_internals)�elem�annotationsr�s ��r+r�z _annotate_columns.<locals>.clone�	sQ����d�J�3�4�4�	6��>�>�+�"2�"2�"4�"4�5�5�D����5��)�)�)��r,r�)�elementr�r�s `@r+r'r'�	sA�������������%��.�.���E��Nr,c���eZdZdddddddddddd�fd�Zd�Zd�Zd�Zed	���Zed
���Z	e
jd���Zd�Z
e
jd
���Ze
jd���Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d �Z!d!�Z"e#j$��Z%d"�Z&e
jd#���Z'e
jd$���Z(e
jd%���Z)d&�Z*d'�Z+	d*d(�Z,d+d)�Z-dS),r�NFTc��dS)NTr�)rMs r+�<lambda>zJoinCondition.<lambda>�	s��D�r,c���||_||_||_||_||_|	|_||_||_||_|
|_	||_
||_||_|
|_
||_||_|���|���|���|���|���|���|���|�|jd��|j�|�|jd��|���|���|���dS�NTF)r�r�r�r�r�r�rCrDrBr�rh�_remote_siderzr�r�r��_determine_joins�_sanitize_joins�
_annotate_fks�_annotate_remote�_annotate_local�_annotate_parentmapper�_setup_pairs�_check_foreign_cols�_determine_direction�_check_remote_side�
_log_joins)rfr�r�r�r�rCrBrDr�r�r�rVrOr�rzr�r�s                 r+r?zJoinCondition.__init__�	sv��&*C��&�'>��$�(@��%�&<��#�"4���!2���&���*���"���(@��%�#5�� �'�����	� 0���(��� 0����������������������������������#�#�%�%�%�������� � ��!1�4�8�8�8���)��$�$�T�%7��?�?�?��!�!�#�#�#����!�!�!��������r,c��|j�dS|jj}|jd|j|j��|jd|j|j��|jd|jd�d�|jD������|jd|jd�d�|jpgD������|jd|jd�d	�|jD������|jd
|jd�d�|j	D������|jd|jd�d
�|j
D������|jd|j|j��dS)Nz%s setup primary join %sz%s setup secondary join %sz%s synchronize pairs [%s]�,c3�.K�|]\}}d|�d|�d�V��dS��(z => rwNr��r��lrFs   r+r�z+JoinCondition._log_joins.<locals>.<genexpr>�	sF������*0�1�a�a����1�1�1�%������r,z#%s secondary synchronize pairs [%s]c3�.K�|]\}}d|�d|�d�V��dSr
r�rs   r+r�z+JoinCondition._log_joins.<locals>.<genexpr>�	sI�������Q���!"���1�1�1�%������r,z%s local/remote pairs [%s]c3�.K�|]\}}d|�d|�d�V��dS)rz / rwNr�rs   r+r�z+JoinCondition._log_joins.<locals>.<genexpr>
sF������)/�!�Q�Q�q�q�q�!�!�!�$������r,z%s remote columns [%s]c3� K�|]	}d|zV��
dS�z%sNr��r�r�s  r+r�z+JoinCondition._log_joins.<locals>.<genexpr>
s&����?�?�C�T�C�Z�?�?�?�?�?�?r,z%s local columns [%s]c3� K�|]	}d|zV��
dSrr�rs  r+r�z+JoinCondition._log_joins.<locals>.<genexpr>
s&����>�>�C�T�C�Z�>�>�>�>�>�>r,z%s relationship direction %s)rz�loggerr]rCrDr�r�r�rVr�r�rF)rfrs  r+rzJoinCondition._log_joins�	s����9���F��i������+�T�Y��8H�I�I�I����-�t�y�$�:L�M�M�M����'��I��H�H���48�4J����
�
�	
�	
�	
�	���1��I��H�H���"�>�D�"����
�
�	
�	
�	
�	���(��I��H�H���37�3J����
�
�	
�	
�	
�	���$��I��H�H�?�?�4�+>�?�?�?�?�?�	
�	
�	
�
	���#��I��H�H�>�>�4�+=�>�>�>�>�>�	
�	
�	
�
	���/���D�N�K�K�K�K�Kr,c��t|jd���|_|j�t|jd���|_dSdS)abremove the parententity annotation from our join conditions which
        can leak in here based on some declarative patterns and maybe others.

        We'd want to remove "parentmapper" also, but apparently there's
        an exotic use case in _join_fixture_inh_selfref_w_entity
        that relies upon it being present, see :ticket:`3364`.

        )rq��valuesN)rrCrDr�s r+r�zJoinCondition._sanitize_joins
s]��,���%6�
�
�
�����)�!1��"�+<�"�"�"�D����*�)r,c
���|j�#|j�tjd|jz���	|jpd}|j�`|j�'t
|j|j|j|���|_|j	�)t
|j
|j|j|���|_	dSdS|j	�)t
|j
|j|j|���|_	dSdS#tj$r�}|j�:tjtjd|j�d|j�d���|���n6tjtjd|jz��|���Yd}~dSYd}~dSd}~wtj$r�}|j�:tjtjd|j�d	|j�d
���|���n6tjtjd|jz��|���Yd}~dSYd}~dSd}~wwxYw)z�Determine 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.)�from_aCould 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.)rDrBrIrJrzr�r r�r�rCr�r��NoForeignKeysErrorr�raise_�AmbiguousForeignKeysError)rfr��nfe�afes    r+r�zJoinCondition._determine_joins'
s�����)�d�n�.D��&�(�*.�)�4���
�S	�'+�'D�'L��$��~�)��%�-�)7��5���!%�!<�1I�	*�*�*�D�&��#�+�'5��6���!%�!=�1I�	(�(�(�D�$�$�$�,�+��#�+�'5��6��5�!%�!=�1I�	(�(�(�D�$�$�$�,�+���(�	�	�	��~�)����-�-�+/�)�)�)�T�^�^�^�E�	�	����������-�>�AE�	�
J������������������������4�/�	�	�	��~�)����4�4� �9�9�9�d�n�n�n�	6��������� ���4�E��)�$�	�	������������!����������	���s,�A,C�.C�G.�A1E�G.�,A1G)�)G.c�.�t|jd���S�N��localr%r)rrCr�s r+r�z%JoinCondition.primaryjoin_minus_local�
s���� 0�9L�M�M�M�Mr,c�.�t|jd���Sr!)rrDr�s r+r�z'JoinCondition.secondaryjoin_minus_local�
s���� 2�;N�O�O�O�Or,c��|jrd�}tj|ji|��S|jrt|jd���St|j��S)a(Return 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��d|jvr6|j���}|d=d|d<|�|��Sd|jvr6|j���}|d=d|d<|�|��SdS)Nr%Tr#)�_annotationsr��_with_annotations)r�ros  r+�replacez9JoinCondition.primaryjoin_reverse_remote.<locals>.replace�
s����w�3�3�3��,�1�1�3�3�A��(��!%�A�g�J�"�4�4�Q�7�7�7��� 4�4�4��,�1�1�3�3�A��'�
�"&�A�h�K�"�4�4�Q�7�7�7�	5�4r,r"r)�_has_remote_annotationsr�replacement_traverserC�_has_foreign_annotationsr)rfr)s  r+r�z(JoinCondition.primaryjoin_reverse_remote�
sv���'�	:�

8�

8�

8��0��1A�2�w�O�O�O��,�
:�'��$�-@�����(��(8�9�9�9r,c�N�tj|i��D]}||jvrdS�dSr�)r�iterater')rfr��
annotationr�s    r+�_has_annotationzJoinCondition._has_annotation�
s?���#�F�B�/�/�	�	�C��S�-�-�-��t�t�.��5r,c�8�|�|jd��S�Nr.�r0rCr�s r+r,z&JoinCondition._has_foreign_annotations�
s���#�#�D�$4�i�@�@�@r,c�8�|�|jd��S�Nr%r3r�s r+r*z%JoinCondition._has_remote_annotations�
s���#�#�D�$4�h�?�?�?r,c�z�|jrdS|jr|���dS|���dS)z�Annotate the primaryjoin and secondaryjoin
        structures with 'foreign' annotations marking columns
        considered as foreign.

        N)r,r��_annotate_from_fk_list�_annotate_present_fksr�s r+r�zJoinCondition._annotate_fks�
sO���(�	��F��(�	)��'�'�)�)�)�)�)��&�&�(�(�(�(�(r,c����fd�}tj�ji|���_�j�"tj�ji|���_dSdS)Nc�H��|�jvr|�ddi��SdS�Nr.T)r�r�r�s �r+�check_fkz6JoinCondition._annotate_from_fk_list.<locals>.check_fk�
s0����d�3�3�3��}�}�i��%6�7�7�7�4�3r,�rr+rCrD)rfr<s` r+r7z$JoinCondition._annotate_from_fk_list�
su���	8�	8�	8�	8�	8�$�8���b�(�
�
�����)�!)�!>��"�B��"�"�D����*�)r,c� ���|j�tj|jj���nt	����fd���fd�}tj|jid|i��|_|j�$tj|jid|i��|_dSdS)Nc���t|tj��rHt|tj��r.|�|��r|S|�|��r|S�r|�vr|�vr|S|�vr|�vr|SdSdSdSr�)r�r�Column�
references)�a�b�
secondarycolss  �r+�
is_foreignz7JoinCondition._annotate_present_fks.<locals>.is_foreign�
s�����!�V�]�+�+�
�
�1�f�m�0L�0L�
��<�<��?�?���H��\�\�!�_�_���H��
��
�%�%�!�=�*@�*@��H��-�'�'�A�]�,B�,B��H�	
�
�(�'�,B�,Br,c����t|jtj��rt|jtj��sdSd|jjvr�d|jjvr��|j|j��}|�~|�|j��r#|j�ddi��|_dS|�|j��r)|j�ddi��|_dSdSdSdSdSr;)r��leftr�
ColumnElement�rightr'�comparer�)�binaryr�rEs  �r+�visit_binaryz9JoinCondition._annotate_present_fks.<locals>.visit_binary�
s	������S�.���
����c�.?�@�@�
������!9�9�9��V�\�%>�>�>� �j���f�l�;�;���?��{�{�6�;�/�/��&,�k�&;�&;�Y��<M�&N�&N��������V�\�2�2��'-�|�'=�'=�&��-�(�(�����:�9�>�>�#�?��r,rK)	rBrr�rMr_rrrCrD)rfrLrErDs  @@r+r8z#JoinCondition._annotate_present_fks�
s������>�%� �O�D�N�,<�=�=�M�M��E�E�M�	�	�	�	�	�	�	�	�	�	�&$�3���b�8�\�":�
�
�����)�!)�!9��"�B��<�(@�"�"�D����*�)r,c�����|j�|j�dg����fd�}tj|jid|i���dS)zvReturn True if the join condition contains column
        comparisons where both columns are in both tables.

        Fc�~��|j|j}}t|tj��r�t|tj��rq��|j��rY��|j��rA��|j��r)��|j��rd�d<dSdSdSdSdSdSdS)NTr)rGrIr�rr��is_derived_from�table)rKrM�f�mt�pt�results   ���r+rLz;JoinCondition._refers_to_parent_table.<locals>.visit_binarys�����;���q�A��1�j�5�6�6�
!��q�*�"9�:�:�
!��&�&�q�w�/�/�
!��&�&�q�w�/�/�	
!�
�&�&�q�w�/�/�
!��&�&�q�w�/�/�

!�!��q�	�	�	�
!�
!�
!�
!�
!�
!�
!�
!�
!�
!�
!�
!r,rKr)r�r�rr�rC)rfrLrRrSrTs  @@@r+�_refers_to_parent_tablez%JoinCondition._refers_to_parent_tablesj�����
�
+��
�
*�����
	!�
	!�
	!�
	!�
	!�
	!�
	!�	��$�*�B��<�0H�I�I�I��a�y�r,c�6�t|j|j��S)z5Return True if parent/child tables have some overlap.)r!r�r�r�s r+�_tables_overlapzJoinCondition._tables_overlap+s!��#��*�D�,I�
�
�	
r,c�p�|jrdS|j�|���dS|js|jr|���dS|���r|�d�d��dS|���r|�	��dS|�
��dS)z�Annotate the primaryjoin and secondaryjoin
        structures with 'remote' annotations marking columns
        considered as part of the 'remote' side.

        Nc��d|jvSr2�r')r�s r+r�z0JoinCondition._annotate_remote.<locals>.<lambda>As��I��)9�9�r,F)r*rB�_annotate_remote_secondaryrhr��_annotate_remote_from_argsrU�_annotate_selfrefrW�_annotate_remote_with_overlap�%_annotate_remote_distinct_selectablesr�s r+r�zJoinCondition._annotate_remote2s����'�	��F��>�%��+�+�-�-�-�-�-�
�
%�		9��):�		9��+�+�-�-�-�-�-�
�
)�
)�
+�
+�	9��"�"�9�9�5�
�
�
�
�
��
!�
!�
#�
#�	9��.�.�0�0�0�0�0��6�6�8�8�8�8�8r,c����fd�}tj�ji|���_tj�ji|���_dS)z^annotate 'remote' in primaryjoin, secondaryjoin
        when 'secondary' is present.

        c�t���jj�|��r|�ddi��SdS�Nr%T)rBrMr�r��r�rfs �r+�replz6JoinCondition._annotate_remote_secondary.<locals>.replNsA����~��/�/��8�8�
;��(�(�(�D�)9�:�:�:�
;�
;r,Nr=�rfrds` r+r[z(JoinCondition._annotate_remote_secondaryHsd���	;�	;�	;�	;�	;�$�8���b�$�
�
���&�:����D�
�
����r,c�^�������fd�}tj�jid|i���_dS)zxannotate 'remote' in primaryjoin, secondaryjoin
        when the relationship is detected as self-referential.

        c����|j�|j��}t|jtj��r�t|jtj��rj�|j��r!|j�ddi��|_�|j��r%|s%|j�ddi��|_dSdSdS�s����dSdSrb)rGrJrIr�rr�r��_warn_non_column_elements)rK�equated�fn�remote_side_givenrfs  ���r+rLz5JoinCondition._annotate_selfref.<locals>.visit_binary_s�����k�)�)�&�,�7�7�G��&�+�z�'>�?�?�	
1�J���j�5�E�E�	
1��2�f�k�?�?�J�"(�+�"7�"7��4�8H�"I�"I�F�K��2�f�l�#�#�L�G�L�#)�<�#9�#9�8�T�:J�#K�#K�F�L�L�L�L�L�L�L�&�
1��.�.�0�0�0�0�0�
1�
1r,rKN)rrrC)rfrjrkrLs``` r+r]zJoinCondition._annotate_selfrefYsT�����	1�	1�	1�	1�	1�	1�	1�$�3���b�8�\�":�
�
����r,c�&��|jr-|jrtjd���d�|jD���n|j�|���r|��fd�d��dS�fd�}t
j|ji|��|_dS)z�annotate '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��g|]\}}|��Sr�r�rs   r+r�z<JoinCondition._annotate_remote_from_args.<locals>.<listcomp>~s��D�D�D��!�Q�1�D�D�Dr,c���|�vSr�r�)r�rOs �r+r�z:JoinCondition._annotate_remote_from_args.<locals>.<lambda>�s���s�k�/A�r,Tc�>��|�vr|�ddi��SdSrb)r�)r�rOs �r+rdz6JoinCondition._annotate_remote_from_args.<locals>.repl�s/����k�)�)�"�,�,�h��-=�>�>�>�*�)r,N)	rhr�rIrJrUr]rr+rC)rfrdrOs  @r+r\z(JoinCondition._annotate_remote_from_argsps�����#�
	,�� �
��*� ����E�D�4�+C�D�D�D�K�K��+�K��'�'�)�)�
	��"�"�#A�#A�#A�#A�4�H�H�H�H�H�
?�
?�
?�
?�
?� (�<�� �"�d� � �D���r,c������fd�}�jduo�jj�jju���fd��tj�jid|i���_dS)z�annotate 'remote' in primaryjoin, secondaryjoin
        when the parent/child tables have some set of
        tables in common, though is not a fully self-referential
        relationship.

        c����|j|j��\|_|_�|j|j��\|_|_dSr�)rGrI)rK�proc_left_rights �r+rLzAJoinCondition._annotate_remote_with_overlap.<locals>.visit_binary�sO���(7����V�\�)�)�%�F�K���)8����f�k�)�)�%�F�L�&�+�+�+r,Nc�H��t|tj��rpt|tj��rV�jj�|��r6�jj�|��r|�ddi��}n��r>|j�	d���j
jur|�ddi��}nT�r>|j�	d���j
jur|�ddi��}n����||fS)Nr%Tr~)
r�rr�r�rMr�r�r�r'r;rzrrh)rGrI�check_entitiesrfs  ��r+rrzDJoinCondition._annotate_remote_with_overlap.<locals>.proc_left_right�s'����$�
� 7�8�8�
1�Z��z�.�>�>�
1��0�2�B�B����>��4�6�F�F�t�L�L�>�"�O�O�X�t�,<�=�=�E���
1��&�*�*�>�:�:�d�i�>N�N�N�����4�(8�9�9����
1��%�)�)�.�9�9�T�Y�=M�M�M��~�~�x��&6�7�7����.�.�0�0�0���;�r,rK)rzrr�rrrC)rfrLrtrrs` @@r+r^z+JoinCondition._annotate_remote_with_overlap�s������	�	�	�	�	�
�I�T�!�N�d�i�&6�d�i�>N�&N�	�	�	�	�	�	�	�.$�3���b�8�\�":�
�
����r,c�R���fd�}tj�ji|���_dS)z}annotate 'remote' in primaryjoin, secondaryjoin
        when the parent/child tables are entirely
        separate.

        c�����jj�|��rU�jj�|��r�jj�|��r|�ddi��SdSdSrb)r�rMr�r�r�r�rcs �r+rdzAJoinCondition._annotate_remote_distinct_selectables.<locals>.repl�s�����,�.�>�>�w�G�G�
;��0�2�B�B�7�K�K�
;��.�0�@�@��I�I�
;��(�(�(�D�)9�:�:�:�	
;�
;�
;�
;r,N)rr+rCres` r+r_z3JoinCondition._annotate_remote_distinct_selectables�sC���	;�	;�	;�	;�	;�$�8���b�$�
�
����r,c�>�tjd|jz��dS)Nz�Non-simple column elements in primary join condition for property %s - consider using remote() annotations to mark the remote side.)rr=rzr�s r+rhz'JoinCondition._warn_non_column_elements�s0���	�
<�>B�i�
H�	
�	
�	
�	
�	
r,c���|�|jd��rdS|jr$tjd�|jD�����ntj|jj����fd�}tj|ji|��|_dS)aCAnnotate 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��g|]\}}|��Sr�r�rs   r+r�z1JoinCondition._annotate_local.<locals>.<listcomp>�s��:�:�:�v��1��:�:�:r,c�T��d|jvr|�vr|�ddi��SdSdS)Nr%r#T)r'r�)r��
local_sides �r+�locals_z.JoinCondition._annotate_local.<locals>.locals_�s?����t�0�0�0�T�Z�5G�5G��~�~�w��o�6�6�6�1�0�5G�5Gr,)	r0rCrhrr�r�rMrr+)rfr|r{s  @r+rzJoinCondition._annotate_local�s�������� 0�'�:�:�	��F��#�	K���:�:��!9�:�:�:���J�J����)G�)I�J�J�J�	7�	7�	7�	7�	7�$�8���b�'�
�
����r,c�d���j�dS�fd�}tj�ji|���_dS)Nc���d|jvr!|�d�jji��Sd|jvr!|�d�jji��SdS)Nr%r~r#)r'r�rzrr�)r�rfs �r+�parentmappers_z<JoinCondition._annotate_parentmapper.<locals>.parentmappers_�s_����4�,�,�,��~�~�~�t�y�7G�&H�I�I�I��D�-�-�-��~�~�~�t�y�7G�&H�I�I�I�.�-r,)rzrr+rC)rfrs` r+rz$JoinCondition._annotate_parentmapper�sU����9���F�	J�	J�	J�	J�	J�$�8���b�.�
�
����r,c�N�|jstjd|j�d����dS)Nria 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.)rVrIrJrzr�s r+rz JoinCondition._check_remote_sides?���&�
	��&�&�(,�y�y�y�3�	�	�	
�
	�
	r,c��d}|�|d��}t|��}|rt|j��}nt|j��}|jr|s	|js|rdS|jr2|r0|s.d|rdpd�d|�d|j�d	�}|d
z
}t
j|���d|rdpd�d|�d|j�d	�}|dz
}t
j|���)
zHCheck the foreign key columns collected and emit error
        messages.Fr.NzbCould not locate any simple equality expressions involving locally mapped foreign key columns for �primaryrBz 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_annotation�boolr�r�r�rzrIrJ)rfr r��can_sync�foreign_cols�has_foreign�errs       r+rz!JoinCondition._check_foreign_colssW�����;�;��I�
�
���<�(�(���	>��D�2�3�3�H�H��D�<�=�=�H�
��	��	��%�	�+6�	�

�F�
��%	,��%	,�X�%	,�%	,��)�	�8�[�8�8�"�N�N��I�I�I��
�
�I�
�C��&�s�+�+�+���)�	�8�[�8�8�"�N�N��I�I�I��
�
��
�C��&�s�+�+�+r,c�B�|j�t|_dStj|jj��}tj|jj��}|�|j	��}|�|j	��}|r�|r�|�
|jdd��}td�|�
|jd��D����}|rK|rI|j
�|j��}|�|��}|�|��}|r|st |_dS|r|st"|_dSt%jd|jz���|rt |_dS|rt"|_dSt%jd|jz���)z[Determine if this relationship is one to many, many to one,
        many to many.

        Nr%r.c�$�g|]
}d|jv�|��S)r%rZ)r�rMs  r+r�z6JoinCondition._determine_direction.<locals>.<listcomp>rs3������$�1�>�9�9�	�:�9�9r,aDCan'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.z�Can't determine relationship direction for relationship '%s' - foreign key columns are present in neither the parent nor the child's mapped tables)rDr
rFrr�r�rMr��intersectionr�r�rCr_r�r�r�rrrIrJrz)rf�
parentcols�
targetcols�onetomany_fk�manytoone_fk�onetomany_local�manytoone_local�self_equateds        r+rz"JoinCondition._determine_directionPs���
��)�'�D�N�N�N����)G�)I�J�J�J����)F�)H�I�I�J�&�2�2�4�3K�L�L�L�&�2�2�4�3K�L�L�L��@
��@
�#'�"F�"F��$�h�	�#�#��#&���!%�!E�!E� �,�i�"�"����#�#��#�O��O�#'�#6�#C�#C��*�$�$�L�'6�&@�&@��&N�&N�O�&5�&@�&@��&N�&N�O�#��?��%.�D�N�N�N�$��_��%.�D�N�N�N� �.�9�<@�9�E�	�	�	��

�!*������
�!*������*�4�7;�i�@���r,c��d�|D��S)z�provide deannotation for the various lists of
        pairs, so that using them in hashes doesn't incur
        high-overhead __eq__() comparisons against
        original columns mapped.

        c�d�g|]-\}}|���|���f��.Sr���_deannotater�s   r+r�z3JoinCondition._deannotate_pairs.<locals>.<listcomp>�s1��J�J�J�t�q�!������!�-�-�/�/�2�J�J�Jr,r�)rf�
collections  r+�_deannotate_pairszJoinCondition._deannotate_pairs�s��K�J�z�J�J�J�Jr,c�0���g}tjg���g}��fd�}�j|f�j|ffD]\}}|��|||���������_��|���_��|���_dS)Nc�8������fd�}t||��dS)Nc����d|jvr6d|jvr-��|��r��||f��n>d|jvr5d|jvr,��|��r��||f��|jtjurZ��||��rFd|jvr��||f��dSd|jvr��||f��dSdSdSdS)Nr%r.)r'r�r^�operatorr�eqr>)rKrGrIr��lrprfs   ���r+rLz<JoinCondition._setup_pairs.<locals>.go.<locals>.visit_binary�s3����� 2�2�2� ��(9�9�9��-�-�d�3�3�:��G�G�T�5�M�*�*�*�*��� 1�1�1� ��(:�:�:��-�-�e�4�4�;��G�G�U�D�M�*�*�*��?�i�l�2�2�t�7L�7L��%�8�8�2�!�E�$6�6�6�"�)�)�4��-�8�8�8�8�8�"�d�&7�7�7�"�)�)�5�$�-�8�8�8�8�8�
3�2�2�2�
8�7r,r")�joincondr�rLr�rfs ` ��r+�goz&JoinCondition._setup_pairs.<locals>.go�s?����
9�
9�
9�
9�
9�
9�
9�*
!��x�8�8�8�8�8r,)r�
OrderedSetrCrDr�rVr�r�)rf�
sync_pairs�secondary_sync_pairsr�r�r�r�s`     @r+rzJoinCondition._setup_pairs�s������
��o�b�!�!��!��	9�	9�	9�	9�	9�	9�2�
�z�*�
�
�!5�6�%
�	%�	%� �H�j�����B�x��$�$�$�$�"&�"8�"8��"=�"=���!%�!7�!7�
�!C�!C���+/�+A�+A� �,
�,
��(�(�(r,c���|jsdSd�|jD��d�|jD��zD�]K\}�t�j��dkr��|jvr$t
j|j|i��|j�<�Lg}|j�}|�	��D]\}}|j
tjvrg|j�
|j��s|�
|jj��r)||ur%||jjvr|�||f����|rEt#jd|j�d|�d��dd��fd	�|D�����d
�	��||j�|j<��MdS)Nc��g|]	\}}||f��
Sr�r��r�r�to_s   r+r�zDJoinCondition._warn_for_conflicting_sync_targets.<locals>.<listcomp>�s-��
�
�
�)�e�S�U�C�L�
�
�
r,c��g|]	\}}||f��
Sr�r�r�s   r+r�zDJoinCondition._warn_for_conflicting_sync_targets.<locals>.<listcomp>�s-��
�
�
�)�e�S�U�C�L�
�
�
r,rrvz' will copy column z to column z(, which conflicts with relationship(s): r�c3�6�K�|]\}}d|�d|�d��d�V��dS)rXz
' (copies z to rwNr�)r��pr�fr_r�s   �r+r�zCJoinCondition._warn_for_conflicting_sync_targets.<locals>.<genexpr>
sP�����&�&�$-�R���=?�B�B����S�S�S� I�&�&�&�&�&�&r,z�. Consider applying viewonly=True to read-only relationships, or provide a primaryjoin condition marking writable columns with the foreign() annotation.)r�r�r��lenrg�_track_overlapping_sync_targets�weakref�WeakKeyDictionaryrzrkrr��_mapper_registryr�r�r`r>rr=r�)rfr�other_props�prop_to_fromr�r�r�s      @r+r�z0JoinCondition._warn_for_conflicting_sync_targets�s���� �	��F�
�
�-1�-C�
�
�
�
�
�-1�-M�
�
�
�
�5	M�5	M�J�E�3��3�#�$�$�q�(�(���$�>�>�>��-�t�y�%�.@�A�A��4����!��#�C�C�H��+�1�1�3�3�6�6�G�B���	�Y�%?�?�?� �I�3�3�B�I�>�>�@� "�/�/��	�0@�A�A�@�
 �u�,�,��d�i�&A�A�A�$�*�*�B��9�5�5�5�����I�I�!�I�I�I�!�E�E��C�C� �I�I�&�&�&�&�1<�&�&�&���������"HM��4�S�9�$�)�D�D�k5	M�5	Mr,c�,�|�d��Sr5��_gather_join_annotationsr�s r+r�zJoinCondition.remote_columns
s���,�,�X�6�6�6r,c�,�|�d��S)Nr#r�r�s r+r�zJoinCondition.local_columns
s���,�,�W�5�5�5r,c�,�|�d��Sr2r�r�s r+r�z!JoinCondition.foreign_key_columns"
s���,�,�Y�7�7�7r,c���t|�|j|����}|j�.|�|�|j|����d�|D��S)Nc�6�h|]}|�����Sr�r�r�s  r+�	<setcomp>z9JoinCondition._gather_join_annotations.<locals>.<setcomp>0
s ��+�+�+�A��
�
���+�+�+r,)r_r�rCrD�update)rfr/�ss   r+r�z&JoinCondition._gather_join_annotations&
sy����0�0��1A�:�N�N�
�
����)�
�H�H��4�4��&�
���
�
�
�
,�+��+�+�+�+r,c�~��t����t�fd�tj|i��D����S)Nc�H��g|]}��|j���|��Sr�)�issubsetr')r�r�r/s  �r+r�zAJoinCondition._gather_columns_with_annotation.<locals>.<listcomp>5
s@���
�
�
���&�&�s�'7�8�8�
��
�
�
r,)r_rr.)rfr�r/s  `r+r�z-JoinCondition._gather_columns_with_annotation2
sS�����_�_�
��
�
�
�
�#�+�F�B�7�7�
�
�
�
�
�	
r,c��t|ddi��}|j|j|j}}}|�
|�||z}n||z}|�r<|��|�d���}t|t
d�����}t||j����|��}	|�Et|t
d������t||j	�����}|	�
|��}n_t|t
d��|j���}|�7|�t|t
d	��|j	�����d}	|�
|��}|	p|}
d|
_nd}
||||
|fS)
a7Given 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.

        r�TN)�flatr#)�
exclude_fn)�equivalents)r�r�r%)rrCrDrBr�r�_ColInAnnotationsr��chainr�r�r�)rfr�r�r�r�rCrDrB�primary_aliasizer�secondary_aliasizerr�s           r+r�zJoinCondition.join_targets<
s��� ,��7��>�
�
��

�����N�%.�]���"��(� -�� ;�
�
�)�K�7���(	"��$�%�O�O��O�6�6�	�$1��*;�G�*D�*D�%�%�%�!�'4�#��1G�'�'�'��%�)�*�*�$�%�0�(5�!�.?��.H�.H�)�)�)��e�%�-�(,�(?������&�!4� <� <�]� K� K�
�
�$1�#�0��9�9� $� 6�%�%�%�!�
%�0�%�+�+�%�-�'8��'B�'B�(,�(?�������'+�#�+�4�4�[�A�A�K�0�E�4E�N�(,�N�%�%�!�N������
�	
r,c�D��	�
��tj���	tj��}|jdu�
�
rItjt
���|jD]'\}}�|�||f��|||<�(n'�s|jD]
\}}|||<�n|jD]
\}}|||<��	�
��fd�}|j}|j��stj
|i|��}|j�4|j}�rtj
|i|��}tj||��}�	fd��	D��}|||fS)Nc����s	d|jvs�r=�r|�vs�s5d|jvr,|�vr tjdd|jd����|<�|SdS)Nr#r%T)r_r�)r'rr�rx)r��binds�
has_secondary�lookuprs ����r+�col_to_bindz5JoinCondition.create_lazy_clause.<locals>.col_to_bind�
s����'�
"�+2�c�6F�+F�+F�$�,G�#�,G�(+�f�}�}�)�(5�.6�#�:J�.J�.J��e�#�#�!$���d�#�(�4�"�"�"�E�#�J��S�z�!��4r,c�,��i|]}�|j|��Sr�)rt)r�r�r�s  �r+�
<dictcomp>z4JoinCondition.create_lazy_clause.<locals>.<dictcomp>�
s!���<�<�<�s�u�S�z�~�s�<�<�<r,)
r�column_dictrD�collections�defaultdict�listrVr>rCrr+rr�)rfr�equated_columnsr
rFr��	lazywhererDrr�r�r�s `       @@@r+�create_lazy_clausez JoinCondition.create_lazy_clause�
s�������� �"�"���*�,�,���*�$�6�
��
	'� �,�T�2�2�F��/�
'�
'���1��q�	� � �!�Q��(�(�(�%&���"�"�
'�#�	'��/�
'�
'���1�%&���"�"�
'��/�
'�
'���1�%&���"�"�	�	�	�	�	�	�	�	�"�$�	���%�->�%� �5��2�{���I���)� �.�M� �
� (� =�!�2�{�!�!�
����M�:�:�I�<�<�<�<�e�<�<�<���+��6�6r,r�)F).r�r�r�r?rr�r�r�r�r�rr�r�r0r,r*r�r7r8rUrWr�r[r]r\r^r_rhrrrrrr�rr�r�r�r�r�r�r�r�r�r�r�r�r,r+r�r��	s6�����������!%����
��(��#/�/�/�/�b&L�&L�&L�P���$g�g�g�R�N�N��X�N��P�P��X�P�
�� :� :��� :�D���
��A�A���A�
��@�@���@�)�)�)����,�,�,�\���0
�
�
�9�9�9�,
�
�
�"
�
�
�.���<-
�-
�-
�^
�
�
�$
�
�
�
�
�
�:
�
�
����@,�@,�@,�DR�R�R�hK�K�K�)
�)
�)
�V'@�g�&?�&A�&A�#�>M�>M�>M�@
��7�7���7�
��6�6���6�
��8�8���8�
,�
,�
,�
�
�
�HL�T
�T
�T
�T
�l37�37�37�37�37�37r,r�c��eZdZdZd�Zd�ZdS)r�zGSeralizable equivalent to:

    lambda c: "name" in c._annotations
    c��||_dSr�)�name)rfr�s  r+r?z_ColInAnnotations.__init__�
s
����	�	�	r,c��|j|jvSr�)r�r')rfrMs  r+�__call__z_ColInAnnotations.__call__�
s���y�A�N�*�*r,N)r�r�r�r�r?r�r�r,r+r�r��
s<��������
���+�+�+�+�+r,r�)3r��
__future__rr�r��rrrr��baserr	�
interfacesr
rrr
rrrrrrrIrrr�
inspectionrrrr�sql.utilrrrrr r!r#r%r.�class_logger�langhelpers�dependency_forr1r'�objectr�r�r�r,r+�<module>r�s>����'�&�&�&�&�&���������������������!�!�!�!�!�!�"�"�"�"�"�"�������"�"�"�"�"�"�!�!�!�!�!�!�!�!�!�!�!�!�&�&�&�&�&�&�+�+�+�+�+�+�������!�!�!�!�!�!� � � � � � ������������������������������� � � � � � �������������������'�'�'�'�'�'�(�(�(�(�(�(�.�.�.�.�.�.�$�$�$�$�$�$�%�%�%�%�%�%�*�*�*�*�*�*�+�+�+�+�+�+����&���(���� � �!<�� �N�N�N%
�N%
�N%
�N%
�N%
�.�N%
�N%
�O�N���N%
�bJ
�
�
�J7�J7�J7�J7�J7�F�J7�J7�J7�Z 
+�
+�
+�
+�
+��
+�
+�
+�
+�
+r,

Hacked By AnonymousFox1.0, Coded By AnonymousFox