
    -h}2                       S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r!  SSK"J#r#  SSK"J$r$  SSK"J%r%  SS K"J&r&  SS!K"J'r'  SS"K"J(r(  SS#K"J)r)  S$ r*S% r+\RX                   " S& S'\5      5       r-S( r. " S) S*\/5      r0 " S+ S,\/5      r1g)-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)_is_mapped_class)PASSIVE_MERGE)	state_str)
MANYTOMANY)	MANYTOONE)	ONETOMANY)PropComparator)StrategizedProperty)_orm_annotate)_orm_deannotate)CascadeOptions   )exc)log)schema)sql)util)inspect)	coercions)
expression)	operators)roles)visitors)_deep_deannotate)_shallow_annotate)adapt_criterion_to_null)ClauseAdapter)join_condition)selectables_overlapvisit_binary_productc                 d    [        [        R                  " [        R                  U 5      SS05      $ )zAnnotate a portion of a primaryjoin expression
with a 'remote' annotation.

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

.. seealso::

    :ref:`relationship_custom_foreign`

    :func:`.foreign`

remoteT_annotate_columnsr   expectr   ColumnArgumentRoleexprs    qC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/orm/relationships.pyr&   r&   6   s.     11488T:J     c                 d    [        [        R                  " [        R                  U 5      SS05      $ )zAnnotate a portion of a primaryjoin expression
with a 'foreign' annotation.

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

.. seealso::

    :ref:`relationship_custom_foreign`

    :func:`.remote`

foreignTr'   r+   s    r-   r0   r0   I   s.     11489d:K r.   c            "       n  ^  \ rS rSrSrSrSrSr\" SSSSSS9r	Sr
SSSSSSSSSSSSSS\	S	   \	S
   S\	S   SSSSSS\	S   \	S   SSSSSSSS4"U 4S jjrS rS r " S S\5      rS7S jr   S8S jrS rS9S jrS rS r\R.                  4S jr S:S jr\S 5       r\S 5       rS r\R@                  \RB                  " S5      S 5       5       r"\R@                  S  5       r#U 4S! jr$S" r%S# r&S$ r'\S% 5       r(\S& 5       r)\R@                  \RB                  " S'5      S( 5       5       r*\RB                  " S5      S) 5       r+\S* 5       r,\,RZ                  S+ 5       r,S, r.S- r/S. r0S/ r1S0 r2\RB                  " S15      S2 5       r3\R@                  S3 5       r4\R@                  S4 5       r5      S;S5 jr6S6r7U =r8$ )<RelationshipProperty]   zDescribes an object property that holds a single item or list
of items that correspond to a related database table.

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

.. seealso::

    :ref:`relationship_config_toplevel`

relationshipTFpassive_deletespassive_updatesenable_typechecksactive_historycascade_backrefsNselectr6   r7   r8   r9   r:   c$                   > [         [        U ]  5         X`l        Xl        X l        X0l        X@l        Xl        SU l	        Xl
        U(       a  U R                  UUUUUS9  U(       a  U"(       a  [        R                  " S5      eU"U l        Xl        UU l        XPl        Xl        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        U#U l        UU l        U!(       a  [>        R@                  " S5        U!U l!        UU l"        UU l#        UU l$        U=(       d    [        RJ                  U l&        U RM                  U S5      U l'        [>        RP                  " U 5        U b  U U l)        SU R                  44U l*        [W        5       U l,        U
(       a&  [W        [Z        R\                  " SU
5      5      U l/        OSU l/        USLa  Xl0        O U R                  (       a  S	U l0        OS
U l0        Xpl1        Xl2        U Rd                  (       a%  U(       a  [        R                  " S5      eSU l3        gXl3        g)a@  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:`tutorial_orm_related_objects` - 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:`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:
  A reference to a string relationship name, or a :func:`_orm.backref`
  construct, which will be used to automatically generate a new
  :func:`_orm.relationship` on the related class, which then refers to
  this one using a bi-directional
  :paramref:`_orm.relationship.back_populates` configuration.

  In modern Python, explicit use of :func:`_orm.relationship` with
  :paramref:`_orm.relationship.back_populates` should be preferred, as
  it is more robust in terms of mapper configuration as well as more
  conceptually straightforward. It also integrates with new :pep:`484`
  typing features introduced in SQLAlchemy 2.0 which is not possible
  with dynamically generated attributes.

  .. seealso::

      :ref:`relationships_backref` - notes on using
      :paramref:`_orm.relationship.backref`

      :ref:`tutorial_orm_related_objects` - in the
      :ref:`unified_tutorial`, presents an overview of bi-directional
      relationship configuration and behaviors using
      :paramref:`_orm.relationship.back_populates`

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


:param back_populates:
  Indicates the name of a :func:`_orm.relationship` on the related
  class that will be synchronized with this one.   It is usually
  expected that the :func:`_orm.relationship` on the related class
  also refer to this one.  This allows objects on both sides of
  each :func:`_orm.relationship` to synchronize in-Python state
  changes and also provides directives to the :term:`unit of work`
  flush process how changes along these relationships should
  be persisted.

  .. seealso::

      :ref:`tutorial_orm_related_objects` - in the
      :ref:`unified_tutorial`, presents an overview of bi-directional
      relationship configuration and behaviors.

      :ref:`relationship_patterns` - includes many examples of
      :paramref:`_orm.relationship.back_populates`.

:param overlaps:
   A string name or comma-delimited set of names of other relationships
   on either this mapper, a descendant mapper, or a target mapper with
   which this relationship may write to the same foreign keys upon
   persistence.   The only effect this has is to eliminate the
   warning that this relationship will conflict with another upon
   persistence.   This is used for such relationships that are truly
   capable of conflicting with each other on write, but the application
   will ensure that no such conflicts occur.

   .. versionadded:: 1.4

   .. seealso::

        :ref:`error_qzyx` - usage example

:param bake_queries=True:
  Legacy parameter, not used.

  .. versionchanged:: 1.4.23 the "lambda caching" system is no longer
     used by loader strategies and the ``bake_queries`` parameter
     has no effect.

: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.

: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.

  .. deprecated:: 1.4 The
     :paramref:`_orm.relationship.cascade_backrefs`
     flag will default to False in all cases in SQLAlchemy 2.0.

  .. 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 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. 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 internally by the
  ``AppenderQuery`` 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 originating relationship for a
  particular state change will not produce state changes within the
  viewonly relationship.   This is the behavior implied by
  :paramref:`_orm.relationship.sync_backref` being set to False.

  .. versionchanged:: 1.3.17 - the
     :paramref:`_orm.relationship.sync_backref` flag is set to False
         when using viewonly in conjunction with backrefs.

  .. 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 will be back-populated only if neither
  sides of a relationship is viewonly.

  .. versionadded:: 1.3.17

  .. versionchanged:: 1.4 - A relationship that specifies
     :paramref:`_orm.relationship.viewonly` automatically implies
     that :paramref:`_orm.relationship.sync_backref` is ``False``.

  .. 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


Nr5   z-sync_backref and viewonly cannot both be Truezsetting 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.lazyz\s*,\s* Fmergezsave-update, mergezCbackref and back_populates keyword arguments are mutually exclusive)4superr2   __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_classr6   r:   r7   remote_sider8   query_class	innerjoindistinct_target_keydocr9   _legacy_inactive_history_style
join_depthr   warn	omit_joinlocal_remote_pairsbake_queriesload_on_pending
Comparatorcomparator_factory
comparatorset_creation_orderinfostrategy_keyset_reverse_propertyresplit	_overlapscascadeorder_byback_populatesbackref)%selfrC   rD   rE   rF   foreign_keysrB   ri   rk   rj   overlapsrG   rh   rI   r=   rP   r6   r7   rQ   r8   rW   r^   rN   rS   rT   rU   r9   r:   r\   r[   _local_remote_pairsrR   ra   rY   rM   rV   	__class__s%                                       r-   rA   RelationshipProperty.__init__y   s   p 	"D24 "&*& 11 / /"3-!1 2  &&?  )	**6' 0. 0.&!2&"#6 ,.L+$II #"5(.A"6"A"A 	 11$=%DI$dii02!$ *h!?@DNDN%"L]]"DL/DL ,**-   DL"Lr.   c                     UR                  5        H4  u  p#X0R                  U   :w  d  M  [        R                  " SU< S35        M6     g )NzSetting z on relationship() while also setting viewonly=True does not make sense, as a viewonly=True relationship does not perform persistence operations. This configuration may raise an error in a future release.)items_persistence_onlyr   rX   )rl   kwkvs       r-   rJ   5RelationshipProperty._warn_for_persistence_only_flags,  s=    HHJDA**1-- 		
 /0	2 r.   c                     [         R                  " UR                  U R                  U R	                  X5      UU R
                  S9  g )N)r_   parententityrU   )r   register_descriptorclass_keyr^   rU   rl   mappers     r-   instrument_class%RelationshipProperty.instrument_class>  s6    &&MMHH..t<	
r.   c                      \ rS rSrSrSrSr   SS jrS r\	R                  S 5       r\	R                  S 5       r\	R                  S	 5       rS
 rS rS rS rS rSrS rSS jrSS jrSS jrS rS rS r\	R                  S 5       rSrg)RelationshipProperty.ComparatoriG  a  Produce boolean, comparison, and other operators for
:class:`.RelationshipProperty` attributes.

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

.. seealso::

    :class:`.PropComparator`

    :class:`.ColumnProperty.Comparator`

    :class:`.ColumnOperators`

    :ref:`types_operators`

    :attr:`.TypeEngine.comparator_factory`

Nr>   c                 N    Xl         X l        X0l        U(       a  X@l        XPl        g)ziConstruction of :class:`.RelationshipProperty.Comparator`
is internal to the ORM's attribute mechanics.

N)prop_parententity_adapt_to_entity_of_type_extra_criteria)rl   r   parentmapperadapt_to_entityof_typeextra_criterias         r-   rA   (RelationshipProperty.Comparator.__init___  s#     I!-$3! '#1 r.   c                 b    U R                  U R                  U R                  UU R                  S9$ )N)r   r   )rp   propertyr   r   )rl   r   s     r-   r   /RelationshipProperty.Comparator.adapt_to_entityr  s2    >>"" /	 "  r.   c                 r    U R                   b  [        U R                   5      $ U R                  R                  $ )zThe 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   r   r   entityrl   s    r-   r   &RelationshipProperty.Comparator.entityz  s-     }}(t}}--}}+++r.   c                 .    U R                   R                  $ )zThe target :class:`_orm.Mapper` referred to by this
:class:`.RelationshipProperty.Comparator`.

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

)r   r   r   s    r-   r   &RelationshipProperty.Comparator.mapper  s     =='''r.   c                 .    U R                   R                  $ N)r   parentr   s    r-   r   -RelationshipProperty.Comparator._parententity  s    =='''r.   c                     U R                   (       a  U R                   R                  $ U R                  R                  R                  $ r   )r   
selectabler   r   _with_polymorphic_selectabler   s    r-   _source_selectable2RelationshipProperty.Comparator._source_selectable  s3    $$,,777}}++HHHr.   c                     U R                  5       nU R                  (       a  [        U R                  5      nOS nU R                  R	                  USUSU R
                  S9u  nnnnnnUb  X4-  $ U$ )NT)source_selectablesource_polymorphicof_type_entityalias_secondaryr   )r   r   r   r   _create_joinsr   )	rl   
adapt_fromr   pjsjsourcedestrD   target_adapters	            r-   __clause_element__2RelationshipProperty.Comparator.__clause_element__  s    002J}}!(!7!% ++",#'- $#33 ,  ~w	r.   c                     [         R                  U R                  U R                  U R                  UU R
                  S9$ )zpRedefine this object in terms of a polymorphic subclass.

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


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

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

.. versionadded:: 1.4

r   )r2   r]   r   r   r   r   r   rl   others     r-   and_$RelationshipProperty.Comparator.and_  sJ     (22"" $ 5 5#33e; 3  r.   c                     [        S5      e)zmProduce an IN clause - this is not implemented
for :func:`_orm.relationship`-based attributes at this time.

zvin_() not yet supported for relationships.  For a simple many-to-one, use in_() against the set of foreign key values.)NotImplementedErrorr   s     r-   in_#RelationshipProperty.Comparator.in_  s    
 &1 r.   c                    [        U[        R                  [        R                  45      (       ab  U R
                  R                  [        [        4;   a  U R                  5       ) $ [        U R
                  R                  SU R                  S95      $ U R
                  R                  (       a  [        R                  " S5      e[        U R
                  R                  XR                  S95      $ )ai  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   rH   r   r	   _criterion_existsr   _optimized_compareadapterrB   rK   InvalidRequestErrorr   s     r-   __eq__&RelationshipProperty.Comparator.__eq__  s    J %$--!ABB==**y*.EE 22444(88 t|| 9  
 &&00= 
 %MM44LL 5  r.   c                 t   [        U SS 5      (       a  [        U R                  5      nUR                  UR                  UR
                  penU R                  R                  (       a  U(       d  UR                  5       nUR                  nUb
  Ub  Xq-  nOUnOSnS nU R                  (       a  U R                  5       nOS nU R                  R                  UUS9u  n	n
nnnnU H>  n[        U R                  R                  R                  U5      X/   :H  nUc  UnM9  UU-  nM@     U
b  [        U	5      U
-  nO[        XR                  R                  S9nUb  U(       a  U(       d  UR!                  U5      nUb  UR#                  SS05      nU[$        R&                  R)                  U5      -  nUbE  [$        R*                  " S5      R-                  U5      R/                  X5      R1                  X5      nU$ [$        R*                  " S5      R-                  U5      R/                  U5      R1                  U5      nU$ )Nr   F)dest_selectabler   )excludeno_replacement_traverseTr   )getattrr   r   r   r   is_aliased_classr   _is_self_referential_anonymous_fromclause_single_table_criterionr   r   r   r|   r   rQ   traverse	_annotater   True__ifnoneexistswhereselect_fromcorrelate_except)rl   	criterionkwargsra   target_mapperto_selectabler   single_critr   r   r   r   r   rD   r   rv   critjexs                      r-   r   1RelationshipProperty.Comparator._criterion_exists$  s   tZ..t}}-KKOO)) /?
 ==55>N$1$G$G$IM+CC* ,$/$;	$/	#(  $||$($;$;$=!$(! ++ -"3 ,  t}}33::A>&)K$ $I )D 0I  ~!"%*!"mm.G.GH %"( +33I>	 $%//.5	 syy((33D$JJqMU4[ [1%%d6	  I JJqMU4[ [&%%d+	  Ir.   c                     U R                   R                  (       d  [        R                  " S5      eU R                  " U40 UD6$ )a/  Produce an expression that tests a collection against
particular criterion, using EXISTS.

An expression like::

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


Will produce a query like::

    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   rB   rK   r   r   rl   r   r   s      r-   any#RelationshipProperty.Comparator.any}  sB    R ==((00- 
 )))>v>>r.   c                     U R                   R                  (       a  [        R                  " S5      eU R                  " U40 UD6$ )a  Produce an expression that tests a scalar reference against
particular criterion, using EXISTS.

An expression like::

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


Will produce a query like::

    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-   has#RelationshipProperty.Comparator.has  s?    8 }}$$00M  )))>v>>r.   c                    U R                   R                  (       d  [        R                  " S5      eU R                   R	                  XR
                  S9nU R                   R                  b  U R                  U5      Ul        U$ )a  Return a simple expression that tests a collection for
containment of a particular item.

:meth:`~.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:`orm_queryguide_joins`
for more details on constructing outer joins.

kwargs may be ignored by this operator but are required for API
conformance.
z9'contains' not implemented for scalar attributes.  Use ==r   )	r   rB   rK   r   r   r   rF   '_Comparator__negated_contains_or_equalsnegation_clause)rl   r   r   clauses       r-   contains(RelationshipProperty.Comparator.contains  s{    v ==((00*  ]]55LL 6 F }}**6)-)J)J*& Mr.   c                   ^  T R                   R                  [        :X  a  [        R                  " U5      nU 4S jnU 4S jnT R                   R
                  (       ap  [        R                  " T R                   R                   VVs/ s H;  u  pV[        R                  " U" U5      U" U" U5      X&5      :g  U" U5      S :H  5      PM=     snn6 $ [        R                  " [        T R                   R                  R                  T R                   R                  R                  U5      5       VVs/ s H	  u  pVXV:H  PM     snn6 nT R                  U5      ) $ s  snnf s  snnf )Nc                    > UR                   n[        R                  " U R                  U R                  STR
                  R                  TR
                  R                  XU5      S9$ )NT)type_unique	callable_)dictr   	bindparamr}   typer   _get_attr_w_warn_on_noner   )	local_colstate
remote_coldict_rl   s       r-   state_bindparamURelationshipProperty.Comparator.__negated_contains_or_equals.<locals>.state_bindparam  sQ    !JJE==!'nn#"&--"H"H MM00%
#	 r.   c                 L   > TR                   (       a  TR                  U 5      $ U $ r   )r   colrl   s    r-   adaptKRelationshipProperty.Comparator.__negated_contains_or_equals.<locals>.adapt*  s    ||#||C00"
r.   )r   rH   r
   r   instance_state_use_getr   r   rZ   or_zipr   primary_keyprimary_key_from_instancer   )rl   r   r   r   r  xyr   s   `       r-   __negated_contains_or_equals<RelationshipProperty.Comparator.__negated_contains_or_equals  s3   }}&&)3"11%8	# ==))88 +/--*J*J +K  GG %a#258U#F!G %aD 0
 +K	 	  #&,,88,,FFuM## F#I **9555)s   AE
-E
c                    [        U[        R                  [        R                  45      (       a\  U R
                  R                  [        :X  a.  [        U R
                  R                  SU R                  S9) 5      $ U R                  5       $ U R
                  R                  (       a  [        R                  " S5      e[        U R                  U5      5      $ )a  Implement the ``!=`` operator.

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

  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   r   r   r   r   r   rH   r
   r   r   r   r   rB   rK   r   r   r   s     r-   __ne__&RelationshipProperty.Comparator.__ne__H  s    N %$--!ABB==**i7(99 t|| :     1133&&009  %T%F%Fu%MNNr.   c                 b    U R                   R                  R                  5         U R                   $ r   )r   r   _check_configurer   s    r-   r   (RelationshipProperty.Comparator.property  s"    II--/99r.   )r   r   r   r   r   )NNr>   r   )__name__
__module____qualname____firstlineno____doc__r   r   rA   r   r   memoized_propertyr   r   r   r   r   r   r   r   __hash__r   r   r   r   r   r   r  r   __static_attributes__r>   r.   r-   r]   r   G  s    	(  !	2&	 
			, 
 	,& 
			( 
 	( 
			( 
 	(	I	4		 
	 8	tW	r/	?b 	?DI	V+	6Z8	Ot 
			 
 	r.   r]   c                     Uc   eS nUb2  [        U5      nUR                  (       a  UR                  R                  nU R	                  USUUS9$ )NT)value_is_parentr   r   )r   r   _adapteradapt_clauser   )rl   instancer   from_entityr   insps         r-   _with_parent!RelationshipProperty._with_parent  s_    ###";'D$$#}}99&& %+	 ' 
 	
r.   c                 4  ^ ^^^	^
 Tb:   [        T5      mTb  [        TSS5      (       d  [        R                  " ST -  5      eU(       + nTc  T R                  XSS9$ U(       d.  T R                  R                  T R                  R                  snmO-T R                  R                  T R                  R                  snmU(       a  T R                  m
OT R                  m
[        R                  " TR                  5       5      m	UU	U
U U4S jnT R                   b9  U(       a2  [#        T R                   R%                  5       5      R'                  U5      n[(        R*                  " U0 SU05      nU(       a  U" U5      nU$ ! [        R                   a    S m GNf = f)Nis_instanceFzMapped instance expected for relationship comparison to object.   Classes, queries and other SQL elements are not accepted in this context; for comparison with a subquery, use %s.has(**criteria).r   c                 t   > U R                   T;   a'  TR                  TTTTU R                      5      U l        g g r   )_identifying_keyr   callable)r   bind_to_colr   r   rl   r   s    r-   visit_bindparam@RelationshipProperty._optimized_compare.<locals>.visit_bindparam  s@    ))[8%)%B%B	 : :;	&	" 9r.   r   )r   rK   NoInspectionAvailabler   rL   _lazy_none_clause_lazy_strategy
_lazywhere_bind_to_col_rev_lazywhere_rev_bind_to_colr   r   r   instance_dictobjrD   r    r   r   r   cloned_traverse)rl   r   r  r   r   reverse_directionr   r,  r+  r   r   s   ``      @@@r-   r   'RelationshipProperty._optimized_compare  s     }GE=%$H$H**. 15	5  !0/=))! *   !##..##00 #I{ ##22##44 #I{
 [[F[[F((5	 	 >>%/%446hy!  ,,rK9
	 $Y/Iq // s   E= =FFc                 |   ^^^^^ TR                  T5      mTR                  TR                  5        UUUUU4S jnU$ )a  Create the callable that is used in a many-to-one expression.

E.g.::

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

    expr = Address.user == u1

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

c                  L  > TR                   TR                     =pU [        R                  LnTR	                  TTTTR
                  (       a  [        R                  O [        R                  [        R                  -  S9nU[        R                  L a0  U(       d(  [        R                  " ST< S[        T5      < S35      eOEU[        R                  L a0  U(       d(  [        R                  " ST< S[        T5      < S35      eOUnUc  [        R                  " ST-  5        U$ )NpassivezCan't resolve value for column z on object z'; no value has been set for this columnz2; the object is detached and the value was expiredzGot None for value of column %s; this is unsupported for a relationship comparison and will not currently produce an IS comparison (but may in a future release))_last_known_valuesr}   r   NO_VALUE_get_state_attr_by_column
persistentPASSIVE_OFFPASSIVE_NO_FETCHINIT_OK	NEVER_SETrK   r   r   PASSIVE_NO_RESULTr   rX   )	
last_known	to_returnexisting_is_availablecurrent_valuecolumnr   r   r   r   s	       r-   _go:RelationshipProperty._get_attr_w_warn_on_none.<locals>._go  s   %*%=%=dhh%GGJ$.j6I6I$I! #<<## #..00:3E3EE = M 
 4 44, 44 "9U#35  - *">">>, 44 &,Yu-=?  - *	 		4 7== r.   )get_property_by_column_track_last_known_valuer}   )rl   r   r   r   rK  rL  r   s    ```` @r-   r   -RelationshipProperty._get_attr_w_warn_on_none  s<    V ,,V4
 	%%dhh/(	 (	T 
r.   c                     U(       d,  U R                   R                  U R                   R                  pCO+U R                   R                  U R                   R                  pC[        X45      nU(       a  U" U5      nU$ r   )r0  r1  r2  r3  r4  r   )rl   r8  r   r   r+  s        r-   r/  &RelationshipProperty._lazy_none_clause7  sl     ##..##00 # ##22##44 #
 ,IC	$Y/Ir.   c                 t    [        U R                  R                  R                  5      S-   U R                  -   $ )N.)strr   r|   r  r}   r   s    r-   __str__RelationshipProperty.__str__I  s+    4;;%%../#5@@r.   c	           	         U(       a  U R                    H  n	X)4U;   d  M    g    SU R                  ;  a  g U R                  U;  a  g U R                  (       Ga_  UR	                  U R                  5      n
U
R                  X#5      nU
R                  (       a  UR                  (       a   e U(       a-  UR	                  U R                  5      R                  XE[        S9  / nU H^  n[        R                  " U5      n[        R                  " U5      nSX~U 4'   UR                  UUUUUS9nUc  MM  UR                  U5        M`     U(       d<  [        R                  " XEU R                  5      nU H  nUR!                  U5        M     g UR	                  U R                  5      R#                  UUUS[        S9  g X0R                     nUbF  [        R                  " U5      n[        R                  " U5      nSX~U 4'   UR                  UUUUUS9nOS nU(       d  UXPR                  '   g UR	                  U R                  5      R#                  XEUS 5        g )Nr?   Tr<  )load
_recursive_resolve_conflict_mapF)_adaptr=  )rd   _cascader}   rB   get_implget_collection
collectionemptygetr   r   r  r5  _mergeappendinit_state_collectionappend_without_eventrc   )rl   sessionsource_statesource_dict
dest_state	dest_dictrY  rZ  r[  rimplinstances_iterable	dest_listcurrentcurrent_statecurrent_dictr6  collcs                      r-   r?   RelationshipProperty.mergeL  s6    ++ $
2 , $--'88;&<<<((2D!%!4!4\!O
 48??)//LL ##DHH-11= 2  I- * 9 9' B)77@48
401nn! )*? %  ?$$S) . !77488 #A--a0 # ##DHH-11 ) 2  "((+G" * 9 9' B)77@48
401nn! )*? %  &)	((###DHH-113r.   c                 P   UR                   U   R                  nUR                  XUS9nU[        R                  L d  Uc  / $ [        US5      (       a7  UR                  XXdS9 Vs/ s H  n[        R                  " U5      U4PM     sn$ [        R                  " U5      U4/$ s  snf )z|Return a list of tuples (state, obj) for the given
key.

returns an empty list if the value is None/empty/PASSIVE_NO_RESULT
r<  r_  )managerrm  rb  r   rF  hasattrr_  r  )rl   r   r   r}   r=  rm  r  os           r-   _value_as_iterable'RelationshipProperty._value_as_iterable  s     }}S!&&HHU7H3
,,,	IT+,, ,,U1,NNA **1-q1N 
  ..q11566s   %"B#c           
   #   V  #    US:w  d  U R                   (       a  [        R                  nO[        R                  nUS:X  a3  UR                  U R
                     R                  R                  X#5      nOU R                  X#U R
                  US9nUS:H  =(       a    SU R                  ;  nU H  u  pX;   a  M  U
c  M  [        R                  " U
5      nU(       a  U" U	5      (       a  M=  U(       a  U	R
                  (       d  MW  U	R                  R                  nUR                  U R                  R                  R                  5      (       d@  [        SU R
                  < SU R                  R                   < SU
R"                  < S	35      eUR%                  U	5        XX4v   M     g 7f)
Ndeletezsave-updater<  zrefresh-expiredelete-orphanzAttribute 'z' on class 'z"' doesn't handle objects of type '')r6   r   PASSIVE_NO_INITIALIZErB  rw  r}   rm  get_all_pendingrz  r]  r5  r   isaclass_managerAssertionErrorr   r|   rp   add)rl   r   r   r   visited_stateshalt_onr=  tuplesskip_pendingr  rt  r5  instance_mappers                r-   cascade_iterator%RelationshipProperty.cascade_iterator  sc     H 4 4 66G ,,GM!]]488,11AA%OF ,,dhh - F
 %%N/*N 	 "(N/y
 &44Q7M7>22N$6$6,44;;O"&&t{{'@'@'G'GHH$ xx!3!3Q[[B  ~.nCC? "(s   F'F)c                 B    U R                   (       a  gU R                  SL$ )NF)rI   rM   r   s    r-   _effective_sync_backref,RelationshipProperty._effective_sync_backref  s    ==$$E11r.   c                     U R                   (       a0  UR                  (       a  [        R                  " SU< SU < S35      eU R                   (       a*  UR                   (       d  UR                  SLa  SUl        g g g g )NRelationship z( cannot specify sync_backref=True since z includes viewonly=True.F)rI   rM   rK   r   )rel_arel_bs     r-   _check_sync_backref(RelationshipProperty._check_sync_backref  sc    >>e00,,-2E; 
 NNNN""%/!&E 0 # r.   c           
         U R                   R                  USS9n[        U[        5      (       d  [        R
                  " SU < SU< S35      eU R                  X5        U R                  X 5        U R                  R                  U5        UR                  R                  U 5        UR                   R                  U R                  5      (       d0  [        R                  " SU< SU < SU< S	U R                  < 35      eU R                  [        [        4;   aG  U R                  UR                  :X  a,  [        R                  " U< S
U < SU R                  < S35      eg g )NF)_configure_mappersz back_populates on relationship 'z' refers to attribute 'z{' that is not a relationship.  The back_populates parameter should refer to the name of a relationship on the target class.zreverse_property z on relationship z references relationship z", which does not reference mapper z and back-reference z  are both of the same direction z<.  Did you mean to set remote_side on the many-to-one side ?)r   get_propertyr   r2   rK   r   r  rd   r  common_parentr   rL   rH   r   r
   )rl   r}   r   s      r-   _add_reverse_property*RelationshipProperty._add_reverse_property  s"   (((G%!566,, !%)  	  - 	  -""5)##D)||))$++66&& eT[[2  NNy)44%//1&& $0  2 5r.   zsqlalchemy.orm.mapperc                    [         R                  R                  n[        U R                  [         R
                  5      (       a!  U R                  U R                  5      " 5       nOb[        U R                  5      (       a<  [        U R                  [        UR                  45      (       d  U R	                  5       nOU R                  n[        U[        5      (       a  UR                  USS9$  [        U5      n[        US5      (       a  U$  [        R                  " SU R                   < S[        U5      < S35      e! [        R                   a     NHf = f)zpReturn the target mapped entity, which is an inspect() of the
class or aliased class that is referred towards.

F	configurer   relationship 'z2' expects a class or a mapper argument (received: ))r   	preloaded
orm_mapperr   rC   string_types_clsregistry_resolve_namer*  r   Mapperclass_mapperr   rx  rK   r.  rL   r}   )rl   	mapperlibrC   r   s       r-   r   RelationshipProperty.entity5  s    NN--	dmmT%6%67755dmmDFHdmm$$ZMMD)"2"23.
 .
 }}H}}Hh%%))(e)DD	X&F vx(( ) "" xxh)
 	
 ++ 		s   -D> >EEc                 .    U R                   R                  $ )zReturn the targeted :class:`_orm.Mapper` for this
:class:`.RelationshipProperty`.

This is a lazy-initializing static attribute.

)r   r   r   s    r-   r   RelationshipProperty.mapperZ  s     {{!!!r.   c                   > U R                  5         U R                  5         U R                  5         U R                  5         U R	                  U R
                  5        U R                  5         U R                  5         U R                  R                  5         [        [        U ]3  5         U R                  S5      U l        g )N))r=   r;   )_check_conflicts_process_dependent_arguments_setup_registry_dependencies_setup_join_conditions_check_cascade_settingsr]  
_post_init_generate_backref_join_condition"_warn_for_conflicting_sync_targetsr@   r2   do_init_get_strategyr0  )rl   rp   s    r-   r  RelationshipProperty.do_initd  s    ))+))+##%$$T]]3 ??A"D13"001FGr.   c                     U R                   R                  R                  R                  U R                  R                  R                  5        g r   )r   r   registry_set_depends_onr   r   s    r-   r  1RelationshipProperty._setup_registry_dependenciesp  s3    ##33KK''	
r.   c                 4   S H  n[        X5      n[        U[        R                  5      (       a$  [	        U UU R                  X!S:H  S9" 5       5        MQ  [        U5      (       d  Mc  [        U5      (       a  Mu  [	        XU" 5       5        M     S HJ  n[        X5      nUc  M  [	        U U[        [        R                  " [        R                  X1S95      5        ML     U R                  bC  [        U R                  5      (       a)  [        R                  " SU R                  < SU < S	35      eU R                   S
LaB  U R                   b5  [#        S [        R$                  " U R                   5       5       5      U l        [        R&                  " S [        R(                  " U R*                  5       5       5      U l        [        R&                  " S [        R(                  " U R,                  5       5       5      U l        U R.                  R0                  U l        g)zrConvert incoming configuration arguments to their
proper form.

Callables are resolved, ORM annotations removed.

)ri   rE   rF   rD   rO   rQ   rD   )favor_tables)rE   rF   Nargnamezsecondary argument z passed to to relationship() z must be a Table object or other FROM clause; can't send a mapped class directly as rows in 'secondary' are persisted independently of a class that is mapped to that same table.Fc              3   j   #    U  H)  n[         R                  " [        R                  US S9v   M+     g7f)ri   r  Nr   r)   r   r*   .0r  s     r-   	<genexpr>DRelationshipProperty._process_dependent_arguments.<locals>.<genexpr>  s3      " 5A   ,,a 5   13c              3   j   #    U  H)  n[         R                  " [        R                  US S9v   M+     g7f)rm   r  Nr  r  s     r-   r  r    s5      :
 I ((!^ Ir  c              3   j   #    U  H)  n[         R                  " [        R                  US S9v   M+     g7f)rQ   r  Nr  r  s     r-   r  r    s3      +
 : ((!] :r  )r   r   r   r  setattr_clsregistry_resolve_argr*  r   r   r   r)   r   r*   rD   rK   rL   ri   tupleto_list
column_setto_column_setrO   rQ   r   persist_selectabletarget)rl   attr
attr_valuevals       r-   r  1RelationshipProperty._process_dependent_argumentsu  s   
D !,J*d&7&78811"1D 2   *%%.>z.J.JJL1'
. 3D$%C#!((!44c 3 >>%*:4>>*J*J&&
 *.	?  ==%$--*C! " dmm4	" DM +/// :
 ''(G(GH	:
 +
'  ?? +
 ''(8(89	+
 
 kk44r.   c                 d   [        S0 SU R                  R                  _SU R                  R                  _SU R                  R                  _SU R                  R                  _SU R
                  _SU R                  _SU R                  _SU R                  R                  _S	U R                  R                  _S
U R                  _SU R                  _SU R                  _SU R                  _SU _SU R                  (       + _SU R                  _6=U l        nUR
                  U l        UR                  U l        UR"                  U l        UR                  U l        UR$                  U l        UR&                  U l        UR(                  U l        UR*                  U l        UR.                  U l        g )Nparent_persist_selectablechild_persist_selectableparent_local_selectablechild_local_selectablerE   rD   rF   parent_equivalentschild_equivalentsconsider_as_foreign_keysrZ   rQ   self_referentialr   support_synccan_be_synced_fnr>   )JoinConditionr   r  r   local_tablerE   rD   rF   _equivalent_columnsr   rO   rZ   rQ   r   rI   _columns_are_mappedr  rH   remote_columnslocal_columnssynchronize_pairsforeign_key_columns_calculated_foreign_keyssecondary_synchronize_pairs)rl   jcs     r-   r  +RelationshipProperty._setup_join_conditions  s   $1 %
&*kk&D&D%
%)[[%C%C%
 %)KK$;$;%
 $(;;#:#:	%

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

,txx
 ,! && HHKK&&//KK&&//	 ,!"r.   c                     U R                   $ )zLReturn the current cascade setting for this
:class:`.RelationshipProperty`.
)r]  r   s    r-   rh   RelationshipProperty.cascade	  s    
 }}r.   c                 &    U R                  U5        g r   )_set_cascaderl   rh   s     r-   rh   r  	  s    '"r.   c                    [        U5      nU R                  (       a`  [        U5      R                  [         R                  5      nU(       a1  [
        R                  " SSR                  [        U5      5      -  5      eSU R                  ;   a  U R                  U5        Xl        U R                  (       a  XR                  l        g g )NzsCascade settings "%s" apply to persistence operations and should not be combined with a viewonly=True relationship., r   )r   rI   rc   
difference_viewonly_cascadesrK   rL   joinsorted__dict__r  r]  _dependency_processorrh   )rl   rh   non_viewonlys      r-   r  !RelationshipProperty._set_cascade	  s     )==w<2211L **$'+yy1E'FH  t}}$((1%%18&&. &r.   c                    UR                   (       a  U R                  (       d  U R                  [        L d  U R                  [        L an  [
        R                  " SU U R                  [        L a  SOSU R                  R                  R                  U R                  R                  R                  S.-  SS9eU R                  S:X  a%  SU;   d  S	U;   a  [
        R                  " S
U -  5      eUR                   (       aT  U R                  R                  5       R                  R                  U R                  U R                  R                  45        g g )Na  For %(direction)s relationship %(rel)s, delete-orphan cascade is normally configured only on the "one" side of a one-to-many relationship, and not on the "many" side of a many-to-one or many-to-many relationship.  To force this relationship to allow a particular "%(relatedcls)s" object to be 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.zmany-to-onezmany-to-many)relrH   clsname
relatedclsbbf0codeallr}  r~  z^On %s, can't set passive_deletes='all' in conjunction with 'delete' or 'delete-orphan' cascade)delete_orphanrN   rH   r	   r
   rK   rL   r   r|   r  r   r6   primary_mapper_delete_orphansrd  r}   r  s     r-   r  ,RelationshipProperty._check_cascade_settings(	  s   !!&&:-91L&&/  ~~2 "/'#{{11::"&++"4"4"="=* - 2 5(?g#=&&;=AB 
   KK&&(88??4;;--. !r.   c                 x    U R                   UR                  ;   =(       a    UR                  U R                      U L $ )zQReturn True if this property will persist values on behalf
of the given mapper.

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

FT)rD   rt  contains_columnr   r  r  )rl   colsrt  s      r-   r  (RelationshipProperty._columns_are_mapped_	  s}    
 A*NN$$44Q77;;1133CC kkmm33A66  r.   c           
         U R                   R                  (       a  gU R                  Gb  U R                  (       Gd  [	        U R                  [
        R                  5      (       a  U R                  0 p!OU R                  u  pU R                  R                  5       nUR                  (       d  [        UR                  5       5      R                  UR                  5      nU HO  nUR                  U5      (       d  M  UR                  (       a  M.  [        R                   " SU< SU < SU< S35      e   U R"                  bM  UR%                  SU R&                  R(                  5      nUR%                  SU R&                  R*                  5      nOUUR%                  SU R&                  R,                  5      nUR%                  SS5      nU(       a  [        R.                  " S5      eUR%                  S	U R0                  5      nU R                   R                  5       n	UR3                  S
U R4                  5        UR3                  SU R6                  5        UR3                  SU R8                  5        UR3                  SU R:                  5        Xl        [=        U	U R"                  UU4UU R>                  S.UD6n
URA                  X5        U R                  (       a  U RC                  U R                  5        gg)zdInterpret the 'backref' instruction to create a
:func:`_orm.relationship` complementary to this one.NzError creating backref 'z' on relationship 'z+': property of that name exists on mapper 'r  rE   rF   zOCan't assign 'secondaryjoin' on a backref against a non-secondary relationship.rm   rI   rG   r7   rM   )rm   rj   )"r   r  rk   rj   r   r   r  r   r  concreterc   iterate_to_rootunionself_and_descendantsr  rK   rL   rD   popr  secondaryjoin_minus_localprimaryjoin_minus_localprimaryjoin_reverse_remoter   rO   
setdefaultrI   rG   r7   rM   r2   r}   _configure_propertyr  )rl   backref_keyr   r   checkmr   r   rm   r   r4   s              r-   r  &RelationshipProperty._generate_backrefp	  sn    ;;""<<#D,?,?,?$,,(9(9::&*llBV&*ll#[[//1F??F2245;;// A~~k221:::$22  +D!5   ~~) ZZ!((BB ZZ#((@@
 ZZ!((CC ZZ6 44@ 
 ":: ? ?L [[//1Fj$--8mT-=-=>/1E1EFnd.?.?@"-/	
 *#xx L &&{A&&t':':; r.   zsqlalchemy.orm.dependencyc                     [         R                  R                  nU R                  c  U R                  [
        LU l        U R                  (       d!  UR                  R                  U 5      U l	        g g r   )
r   r  orm_dependencyrB   rH   r
   rI   DependencyProcessorfrom_relationshipr  )rl   
dependencys     r-   r  RelationshipProperty._post_init	  sV    ^^22
<<>>:DL}}..@@0 & r.   c                 2    U R                   nUR                  $ )zHmemoize the 'use_get' attribute of this RelationshipLoader's
lazyloader.)r0  use_get)rl   strategys     r-   r  RelationshipProperty._use_get	  s    
 &&r.   c                 L    U R                   R                  U R                  5      $ r   )r   r  r   r   s    r-   r   )RelationshipProperty._is_self_referential	  s    {{((55r.   c                    SnU(       a  U R                   b  SnUc8  U(       a1  U R                  R                  (       a  U R                  R                  nU(       a  UR                  nUc  UR
                  nSnOU R                  nUcZ  U R                  R
                  nU R                  R                  (       a  SnU R                  (       a  Uc  UR                  5       nSnO5X0R                  R                  Ld  U R                  R                  (       a  SnUR                  n	U=(       d6    US L=(       a+    UU R                  R                  L=(       d    UR                  nU R                  R                  UUUU	U5      u  n
nnnnUc  U R                  R                  nUc  U R                  R                  nU
UUUUU4$ )NFT)rD   r   with_polymorphicr   r   r   r   r   r   r   _is_subqueryr  join_targetsr  )rl   r   r   r   r   r   r   aliaseddest_mapperr   rE   rF   rD   r   s                 r-   r   "RelationshipProperty._create_joins	  s    t~~9G$!dkk&B&B$(KK$L$L!(//K&"0";";++K""kk44O{{++((->-F"1"G"G"I;;#K#KK{{++G!99 
T) !{{??@ 2$11 	   --
	
 $ $ 7 7""kk55O
 	
r.   )0r  r]  r  r  r0  rV   rg   rd   rO   r9   rC   rj   rk   r[   rh   r:   rP   r_   r^   rH   rT   rU   r8   ra   rS   rW   r=   r\   r  rZ   rY   ri   r6   r7   rG   rE   rR   rQ   rD   r  rF   rN   rb   rM   r  r  rB   rI   )TN)FNT)FNr   )FNNNFr>   )9r  r  r  r  r  strategy_wildcard_keyinherit_cache_links_to_entityr   rt   r  rA   rJ   r   r   r]   r$  r   r   r/  rV  r?   r   rB  rz  r  r   r  staticmethodr  r  r   r  preload_moduler   r   r  r  r  r  r  r  r  r  rh   setterr  r  r  r  r  r  r  r   r   r  __classcell__)rp   s   @r-   r2   r2   ]   s   	 +M !
 )*;<)*;<+,?@ ()9:*+=> ',Iq#f$
~^ ~@
" BH\|$A\~ *4)?)?7, <@6Dp 2 2 ' ''R 
	01!
 2 !
F 
" "
H

P5dJ: . . . . 
	563 7 3
 
01 2(   ^^# #9**X	
"K<Z 
45 6 
    
6 6
 !K
 K
r.   r2   c                 2   ^^ UU4S jmU b  T" U 5      n S mU $ )Nc                    > [        U [        R                  5      (       a  U R                  TR	                  5       5      n U R                  TS9  U $ )N)clone)r   r   ColumnClauser   copy_copy_internals)elemannotationsrI  s    r-   rI   _annotate_columns.<locals>.clone#
  sC    dJ3344>>+"2"2"45D5)r.   r>   )elementrN  rI  s    `@r-   r(   r(   "
  s#     .ENr.   c                      \ rS rSrSSSSSSSSSSSS 4S jrS rS rS	 r\S
 5       r	\S 5       r
\R                  S 5       rS r\R                  S 5       r\R                  S 5       rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S  r!S! r"S" r#\$RJ                  " 5       r&S# r'\R                  S$ 5       r(\R                  S% 5       r)\R                  S& 5       r*S' r+S( r,  S,S) jr-S-S* jr.S+r/g).r  i/
  NFTc                      g)NTr>   )rt  s    r-   <lambda>JoinCondition.<lambda>A
  s    Dr.   c                    Xl         X0l        X l        X@l        Xl        Xl        XPl        Xpl        X`l        Xl	        Xl
        Xl        Xl        Xl        Xl        UU l        U R!                  5         U R#                  5         U R%                  5         U R'                  5         U R)                  5         U R+                  5         U R-                  5         U R/                  U R                  S5        U R                  b  U R/                  U R                  S5        U R1                  5         U R3                  5         U R5                  5         g NTF)r  r  r  r  r  r  rE   rF   rD   r  ro   _remote_sider   r  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)rl   r  r  r  r  rE   rD   rF   r  r  r  rZ   rQ   r  r   r  r  s                    r-   rA   JoinCondition.__init__0
  s   & *C&'>$(@%&<#"4!2&*"(@%#5 '	 0( 0##%  !1!148)$$T%7%7?!!#!r.   c           	         U R                   c  g U R                   R                  nUR                  " SU R                   U R                  5        UR                  " SU R                   U R                  5        UR                  " SU R                   SR                  S U R                   5       5      5        UR                  " SU R                   SR                  S U R                  =(       d    /  5       5      5        UR                  " SU R                   SR                  S	 U R                   5       5      5        UR                  " S
U R                   SR                  S U R                   5       5      5        UR                  " SU R                   SR                  S U R                   5       5      5        UR                  " SU R                   U R                  5        g )Nz%s setup primary join %sz%s setup secondary join %sz%s synchronize pairs [%s],c              3   <   #    U  H  u  pS U< SU< S3v   M     g7f(z => r  Nr>   r  lrl  s      r-   r  +JoinCondition._log_joins.<locals>.<genexpr>j
  s      4J&1a1%4J   z#%s secondary synchronize pairs [%s]c              3   <   #    U  H  u  pS U< SU< S3v   M     g7frg  r>   ri  s      r-   r  rk  q
  s       DFQ !"1%Drl  z%s local/remote pairs [%s]c              3   <   #    U  H  u  pS U< SU< S3v   M     g7f)rh  z / r  Nr>   ri  s      r-   r  rk  y
  s      3J!Qq!$3Jrl  z%s remote columns [%s]c              3   ,   #    U  H
  nS U-  v   M     g7fz%sNr>   r  r  s     r-   r  rk  
  s     ?+>CTCZ+>   z%s local columns [%s]c              3   ,   #    U  H
  nS U-  v   M     g7frp  r>   rq  s     r-   r  rk  
  s     >+=CTCZ+=rr  z%s relationship direction %s)r   loggerra   rE   rF   r  r  r  rZ   r  r  rH   )rl   r   s     r-   rb  JoinCondition._log_joinsa
  sz   99ii+TYY8H8HI-tyy$:L:LM'IIHH 484J4J 	
 	1IIHH ">>D"D 	
 	(IIHH 373J3J 	
 	$IIHH?4+>+>??	

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

 	/DNNKr.   c                     [        U R                  SS9U l        U R                  b  [        U R                  SS9U l        gg)a:  remove 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`.

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

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

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

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

c                     SU R                   ;   a.  [        U R                   5      nUS	 SUS'   U R                  U5      $ SU R                   ;   a.  [        U R                   5      nUS	 SUS'   U R                  U5      $ g )Nr&   Tr  )_annotationsr   _with_annotations)rP  rw   s     r-   replace9JoinCondition.primaryjoin_reverse_remote.<locals>.replace  s    w333W112A(!%AgJ"44Q77 4 44W112A'
"&AhK"44Q77	 5r.   r  rx  )_has_remote_annotationsr   replacement_traverserE   _has_foreign_annotationsr   )rl   r  s     r-   r&  (JoinCondition.primaryjoin_reverse_remote  sd     ''
8 001A1A2wOO,,'$$-@  ((8(899r.   c                 b    [         R                  " U0 5       H  nX#R                  ;   d  M    g   grV  )r   iterater  rl   r   
annotationr  s       r-   _has_annotationJoinCondition._has_annotation/  s-    ##FB/C--- 0 r.   c                 :    U R                  U R                  S5      $ Nr0   r  rE   r   s    r-   r  &JoinCondition._has_foreign_annotations6  s    ##D$4$4i@@r.   c                 :    U R                  U R                  S5      $ Nr&   r  r   s    r-   r  %JoinCondition._has_remote_annotations:  s    ##D$4$4h??r.   c                     U R                   (       a  gU R                  (       a  U R                  5         gU R                  5         g)zyAnnotate the primaryjoin and secondaryjoin
structures with 'foreign' annotations marking columns
considered as foreign.

N)r  r  _annotate_from_fk_list_annotate_present_fksr   s    r-   rZ  JoinCondition._annotate_fks>  s1     (((('')&&(r.   c                    ^  U 4S jn[         R                  " T R                  0 U5      T l        T R                  b(  [         R                  " T R                  0 U5      T l        g g )Nc                 L   > U TR                   ;   a  U R                  SS05      $ g Nr0   T)r  r   r  s    r-   check_fk6JoinCondition._annotate_from_fk_list.<locals>.check_fkM  s*    d333}}i%677 4r.   r   r  rE   rF   )rl   r  s   ` r-   r  $JoinCondition._annotate_from_fk_listL  s]    	8 $88b(
 )!)!>!>""B"D *r.   c                 d  ^^ U R                   b+  [        R                  " U R                   R                  5      mO
[	        5       mU4S jmU4S jn[
        R                  " U R                  0 SU05      U l        U R                  b*  [
        R                  " U R                  0 SU05      U l        g g )Nc                 ,  > [        U [        R                  5      (       aO  [        U[        R                  5      (       a0  U R                  U5      (       a  U $ UR                  U 5      (       a  U$ T(       a  U T;   a  UT;  a  U $ UT;   a	  U T;  a  U$ g g g r   )r   r   Column
references)absecondarycolss     r-   
is_foreign7JoinCondition._annotate_present_fks.<locals>.is_foreign_  s    !V]]++
1fmm0L0L<<??H\\!__H%!=*@H-'A],BH -C' r.   c                 f  > [        U R                  [        R                  5      (       a)  [        U R                  [        R                  5      (       d  g SU R                  R
                  ;  a  SU R                  R
                  ;  a  T" U R                  U R                  5      nUb  UR                  U R                  5      (       a#  U R                  R                  SS05      U l        g UR                  U R                  5      (       a#  U R                  R                  SS05      U l        g g g g g r  )r   leftr   ColumnElementrightr  comparer   )binaryr  r  s     r-   visit_binary9JoinCondition._annotate_present_fks.<locals>.visit_binaryl  s    S.. c.?.?@@ !9!99V\\%>%>> fll;?{{6;;//&,kk&;&;Y<M&NV\\22'-||'='=&-( 3 # ? :r.   r  )	rD   r   r  rt  rc   r   r7  rE   rF   )rl   r  r  r  s     @@r-   r  #JoinCondition._annotate_present_fksY  s    >>% OODNN,<,<=MEM		& $33b8\":
 )!)!9!9""B<(@"D *r.   c                    ^^^ U R                   mU R                  mS/mUUU4S jn[        R                  " U R                  0 SU05        TS   $ )zfReturn True if the join condition contains column
comparisons where both columns are in both tables.

Fc                   > U R                   U R                  p![        U[        R                  5      (       a  [        U[        R                  5      (       a  TR                  UR                  5      (       ai  TR                  UR                  5      (       aH  TR                  UR                  5      (       a'  TR                  UR                  5      (       a  STS'   g g g g g g g )NTr   )r  r  r   r   rJ  is_derived_fromtable)r  rt  fmtptresults      r-   r  ;JoinCondition._refers_to_parent_table.<locals>.visit_binary  s    ;;q1j5566q*"9"9::&&qww//&&qww//&&qww//&&qww// q	 0 0 0 0 ; 7r.   r  r   )r  r  r   r   rE   )rl   r  r  r  r  s     @@@r-   _refers_to_parent_table%JoinCondition._refers_to_parent_table  sP    
 ++**
	! 	$**B<0HIayr.   c                 B    [        U R                  U R                  5      $ )z5Return True if parent/child tables have some overlap.)r"   r  r  r   s    r-   _tables_overlapJoinCondition._tables_overlap  s"     #**D,I,I
 	
r.   c                    U R                   (       a  gU R                  b  U R                  5         gU R                  (       d  U R                  (       a  U R                  5         gU R                  5       (       a  U R                  S S5        gU R                  5       (       a  U R                  5         gU R                  5         g)zAnnotate the primaryjoin and secondaryjoin
structures with 'remote' annotations marking columns
considered as part of the 'remote' side.

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

c                    > TR                   R                  R                  U 5      (       a  U R                  SS05      $ g Nr&   T)rD   rt  r  r   rP  rl   s    r-   repl6JoinCondition._annotate_remote_secondary.<locals>.repl  s9    ~~//88(((D)9:: 9r.   Nr  rl   r  s   ` r-   r  (JoinCondition._annotate_remote_secondary  sL    	; $88b$
 &::D
r.   c                 l   ^ ^^ UUU 4S jn[         R                  " T R                  0 SU05      T l        g)zhannotate 'remote' in primaryjoin, secondaryjoin
when the relationship is detected as self-referential.

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

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

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

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

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

r  Nc                 Z   > SU R                   ;  a  U T;   a  U R                  SS05      $ g g )Nr&   r  T)r  r   )rM  
local_sides    r-   locals_.JoinCondition._annotate_local.<locals>.locals_a  s4    t000TZ5G~~wo66 6H0r.   )	r  rE   ro   r   r  r  rt  r   r  )rl   rj  rl  r  r  s       @r-   r\  JoinCondition._annotate_localL  s      0 0'::##!%!9!9:!9v!9:J )G)G)I)IJJ	7 $88b'
 ;s   C
c                 |   ^  T R                   c  g U 4S jn[        R                  " T R                  0 U5      T l        g )Nc                    > SU R                   ;   a'  U R                  STR                  R                  05      $ SU R                   ;   a'  U R                  STR                  R                  05      $ g )Nr&   r   r  )r  r   r   r   r   )rM  rl   s    r-   parentmappers_<JoinCondition._annotate_parentmapper.<locals>.parentmappers_m  s`    4,,,~~~tyy7G7G&HIID---~~~tyy7G7G&HII .r.   )r   r   r  rE   )rl   r  s   ` r-   r]  $JoinCondition._annotate_parentmapperi  s8    99	J $88b.
r.   c                 x   U R                   (       d%  [        R                  " SU R                  < S35      e[        R
                  " U R                  R                  5      R                  U R                  R                  5      nU R                    H'  u  p#X1;   d  M  [        R                  " SU< S35        M)     g )Nr  a   could not determine any unambiguous local/remote column pairs based on join condition and remote_side arguments.  Consider using the remote() annotation to accurately mark those elements of the join condition that are on the remote side of the relationship.zExpression z is marked as 'remote', but these column(s) are local to the local side.  The remote() annotation is needed only for a self-referential relationship where both sides of the relationship refer to the same tables.)rZ   rK   rL   r   r   r  r  rt  r  r  rX   )rl   
not_target_rmts       r-   ra   JoinCondition._check_remote_sidew  s    &&&& (,yy3	 	 ..00j66889  11$II ! 2r.   c                 \   SnU R                  US5      n[        U5      nU(       a  [        U R                  5      nO[        U R                  5      nU R                  (       a  U(       d  U R                  (       d  U(       a  gU R                  (       aT  U(       aM  U(       dF  SU=(       a    S=(       d    S< SU< SU R
                  < S	3nUS
-  n[        R                  " U5      eSU=(       a    S=(       d    S< SU< SU R
                  < S	3nUS-  n[        R                  " U5      e)z@Check the foreign key columns collected and emit error
messages.Fr0   NzbCould not locate any simple equality expressions involving locally mapped foreign key columns for primaryrD   z join condition 'z' on relationship rT  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  r   rK   rL   )rl   r!   r  can_syncforeign_colshas_foreignerrs          r-   r_  !JoinCondition._check_foreign_cols  s    ;;I
 <(D223HD<<=H %%+
 X )	8[8"II  IC &&s++ )	8[8"II  C &&s++r.   c                 &   U R                   b  [        U l        g[        R                  " U R
                  R                  5      n[        R                  " U R                  R                  5      nUR                  U R                  5      nUR                  U R                  5      nU(       Ga  U(       Ga  U R                  U R                  SS5      n[        U R                  U R                  S5       Vs/ s H  nSUR                  ;  d  M  UPM     sn5      nU(       aN  U(       aG  U R                  R                  U R                  5      nUR!                  U5      nUR!                  U5      nU(       a  U(       d  ["        U l        gU(       a  U(       d  [$        U l        g[&        R(                  " SU R*                  -  5      eU(       a  ["        U l        gU(       a  [$        U l        g[&        R(                  " SU R*                  -  5      es  snf )zKDetermine if this relationship is one to many, many to one,
many to many.

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

)_deannotate)rl   r`  r  r  s       r-   _deannotate_pairsJoinCondition._deannotate_pairs*  s1     @JJztq!--/2zJJJs   ,6c                 2  ^ ^ / n[         R                  " / 5      m/ nUU 4S jnT R                  U4T R                  U44 H  u  pEUc  M
  U" XE5        M     T R	                  T5      T l        T R	                  U5      T l        T R	                  U5      T l        g )Nc                 .   >^ UUU4S jn[        X 5        g )Nc                   > SUR                   ;   a9  SUR                   ;  a)  TR                  U5      (       a  TR                  X45        OHSUR                   ;   a8  SUR                   ;  a(  TR                  U5      (       a  TR                  X!45        U R                  [        R
                  L a^  TR                  X5      (       aG  SUR                   ;   a  TR                  X45        g SUR                   ;   a  TR                  X!45        g g g g )Nr&   r0   )r  r  r  operatorr   eqrd  )r  r  r  r`  lrprl   s      r-   r  <JoinCondition._setup_pairs.<locals>.go.<locals>.visit_binary9  s     2 22 (9(99--d33GGTM* 1 11 (:(::--e44GGUM*??ill2t7L7L8 8 !E$6$66"))4-8"d&7&77"))5-8 882r.   r#   )joincondr`  r  r&  rl   s    ` r-   go&JoinCondition._setup_pairs.<locals>.go8  s    9* !8r.   )r   
OrderedSetrE   rF   r  rZ   r  r  )rl   
sync_pairssecondary_sync_pairsr)  r(  r`  r&  s   `     @r-   r^  JoinCondition._setup_pairs3  s    
oob!!	92 z*!56%
 H x$%
 #'"8"8"=!%!7!7
!C+/+A+A ,
(r.   c                   ^ U R                   (       d  g U R                   VVs/ s H  u  pX4PM
     snnU R                   VVs/ s H  u  pX4PM
     snn-    GH  u  nmTU R                  ;  a1  [        R
                  " U R                  U05      U R                  T'   MH  / nU R                  T   nUR                  5        GH   u  pVUR                  R                  (       a  M#  XPR                  R                  ;  d  M>  UR                  U R                  R                  ;  d  Md  U R                  R                  UR                  ;  d  M  SU R                  R                  ;  d  M  SUR                  ;  d  M  U R                  R                  R                  UR                  5      (       a  M  U R                  R                  R                  UR                  5      (       a  GM%  U R                  R                  R                  UR                  5      (       a  GM\  U R                  R                  R                  UR                  5      (       a  GM  U R                  R                  UR                  :w  d7  U R                  R                  R                  UR                  5      (       a  GM  UR!                  XV45        GM     U(       a  ["        R$                  " SU R                  < SU< ST< SSR'                  [)        U4S jU 5       5      5      < SS	R'                  [)        S
 U 5       5      5      < SU R                  < S3SS9  XR                  T   U R                  '   GM     g s  snnf s  snnf )Nz__*r  z' will copy column z to column z(, which conflicts with relationship(s): r  c              3   F   >#    U  H  u  pS U< SU< ST< S3v   M     g7f)r  z
' (copies z to r  Nr>   )r  prfr_to_s      r-   r  CJoinCondition._warn_for_conflicting_sync_targets.<locals>.<genexpr>  s%      '"5@	S ACC$M5@s   !a  . If this is not the intention, consider if these relationships should be linked with back_populates, or if viewonly=True should be applied to one or more if they are read-only. For the less common case that foreign key constraints are partially overlapping, the orm.foreign() annotation can be used to isolate the columns that should be written towards.   To silence this warning, add the parameter 'overlaps="re  c              3   >   #    U  H  u  pUR                   v   M     g 7fr   )r}   )r  r1  frs      r-   r  r4    s     +MvrBFFs   z"' to the 'z' relationship.qzyxr  )r  r  r  _track_overlapping_sync_targetsweakrefWeakKeyDictionaryr   rs   r   _dispose_calledrd   r}   rg   r   
is_siblingr  rd  r   rX   r  r  )rl   r}  r3  other_propsprop_to_fromr1  r2  s     `    r-   r  0JoinCondition._warn_for_conflicting_sync_targets`  s      .2-C-C
-C\eUL-C
 .2-M-M
-M\eUL-M

JE3 $>>> --tyy%.@A 44 !#CCCH+113GBII555ii&A&AAFF$))*=*== IIMM= ")<)<<!5 $		 0 0 ; ;BII F F $		 0 0 ; ;BII F F $		 0 0 ; ;BII F F $		 0 0 ; ;BII F F IIMMRVV3#'99#3#3#A#A"))#L#L $**B951  44 II !II! II & '"5@'" !"  HHV+M+M%MN II14 $7: HM44S9$))DY
 

s   M2M8c                 $    U R                  S5      $ r  _gather_join_annotationsr   s    r-   r  JoinCondition.remote_columns  s    ,,X66r.   c                 $    U R                  S5      $ )Nr  rA  r   s    r-   r  JoinCondition.local_columns  s    ,,W55r.   c                 $    U R                  S5      $ r  rA  r   s    r-   r  !JoinCondition.foreign_key_columns  s    ,,Y77r.   c                    [        U R                  U R                  U5      5      nU R                  b+  UR	                  U R                  U R                  U5      5        U Vs1 s H  o3R                  5       iM     sn$ s  snf r   )rc   r  rE   rF   updater  )rl   r  sr  s       r-   rB  &JoinCondition._gather_join_annotations  ss    001A1A:N
 )HH44&&

 *++A+++s   "A>c                     [        U5      n[        [        R                  " U0 5       Vs/ s H'  nUR                  UR                  5      (       d  M%  UPM)     sn5      $ s  snf r   )rc   r   r  issubsetr  r  s       r-   r  -JoinCondition._gather_columns_with_annotation  s[    _
 $++FB77C&&s'7'78 7
 	
s   $AAc                    [        USS05      nU R                  U R                  U R                  pnUb  Ub  Xt-  nOXd-  nU(       a0  Ub  U[        R
                  " U6 -  nOU[        R
                  " U6 -  nU(       Ga  Ub  UR                  SS9n[        U[        S5      S9n	[        X R                  S9R                  U	5      n
Ub4  [        U[        S5      S9R                  [        UU R                  S95      n	U
R                  U5      nOP[        U[        S5      U R                  S9n	Ub-  U	R                  [        U[        S	5      U R                  S95        Sn
U	R                  U5      nU
=(       d    U	nSUl        OSnUUUUU4$ )
a  Given a source and destination selectable, create a
join between them.

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

r   TN)flatr  )
exclude_fn)equivalents)rQ  rR  r&   )r   rE   rF   rD   r   r   r   r    _ColInAnnotationsr  chainr  r   rQ  )rl   r   r   r=  r   r   rE   rF   rD   primary_aliasizersecondary_aliasizerr   s               r-   r<  JoinCondition.join_targets  s   * ,7>

 NN %. "( - ;)7( -.0I I)CHHn,EE$%;;;F	$1*;G*D%! '4#1G1G'%)* $ %0(5!.?.H)e%-(,(?(? & !4 < <] K$1#09 $ 6 6%!
 %0%++%-'8'B(,(?(? '+#+44[AK0E4EN(,N%!N
 	
r.   c                   ^^
^^ [         R                  " 5       m
[         R                  " 5       nU R                  S LmT(       aI  [        R                  " [
        5      mU R                   H  u  p4TU   R                  X445        X2U'   M      O:T(       d  U R                   H	  u  p4X2U'   M     OU R                   H	  u  p4XBU'   M     U
UUU4S jnU R                  nU R                  b  T(       d  [        R                  " U0 U5      nU R                  bA  U R                  nT(       a  [        R                  " U0 U5      n[        R                  " Xg5      nT
 Vs0 s H  nT
U   R                  U_M     n	nXiU4$ s  snf )Nc                    > T(       d  SU R                   ;   d+  T(       aS  T(       a  U T;   d  T(       d?  SU R                   ;   a/  U T;  a$  [        R                  " S S U R                  SS9TU '   TU    $ g )Nr  r&   T)r   r   )r  r   r   r   )r  bindshas_secondarylookupr8  s    r-   col_to_bind5JoinCondition.create_lazy_clause.<locals>.col_to_bindL  si     '7c6F6F+F$"sf})h#:J:J.J e#!$d#((4"E#J Sz!r.   )r   column_dictrF   collectionsdefaultdictlistrZ   rd  rE   r   r  r   r   r}   )rl   r8  equated_columnsrj  rl  r]  	lazywhererF   r  r+  rZ  r[  r\  s    `        @@@r-   create_lazy_clause JoinCondition.create_lazy_clause:  s\     "**,**$6 ,,T2F//q	  !(%&" 0 #//%&" 0 //%&" 0	 	" $$	%-> 552{I ) ..M  ( = =!2{! :I6;<esuSz~~s*e<66 =s   E:)ro   rW  r  r  r  r  r  rH   rZ   r  r  r  rE   r   rD   r  rF   r  r  r  )Nr>   )F)0r  r  r  r  rA   rb  rY  rX  r   r%  r$  r   r  r&  r  r  r  rZ  r  r  r  r  r[  r  r  r  r  r  r  r\  r]  ra  r_  r`  r  r^  r9  r:  r8  r  r  r  r  rB  r  r<  re  r  r>   r.   r-   r  r  /
  s    !%(#/b&LP$gR N N P P 
 :  :D 
A A 
@ @),\0
9,
"
.@-
^
$

:
:@,DRhK)
V '.&?&?&A#UMn 
7 7 
6 6 
8 8
,
 _
B37r.   r  c                   (    \ rS rSrSrSrS rS rSrg)rS  ip  z<Serializable object that tests for a name in c._annotations.namec                     Xl         g r   rh  )rl   ri  s     r-   rA   _ColInAnnotations.__init__u  s    	r.   c                 4    U R                   UR                  ;   $ r   )ri  r  )rl   rt  s     r-   __call___ColInAnnotations.__call__x  s    yyANN**r.   N)	r  r  r  r  r  	__slots__rA   rm  r  r>   r.   r-   rS  rS  p  s    FI+r.   rS  )2r  
__future__r   r`  re   r9   r   baser   r   r   
interfacesr	   r
   r   r   r   r   r   r   r   r   rK   r   r   r   
inspectionr   r   r   r   r   r   sql.utilr   r   r   r    r!   r"   r$   r&   r0   class_loggerr2   r(   objectr  rS  r>   r.   r-   <module>rx     s    '  	   "   " ! ! & +  !               ' ( . $ % * +&( A'
. A'
 A'
HN
~7F ~7B"	+ 	+r.   