
H`Tc           @@  s  d  Z  d d l m Z d d l m Z m Z m Z m Z m	 Z	 d d l m
 Z
 m Z m Z d d l m Z d d l m Z d d	 l m Z m Z m Z m Z m Z m Z d d
 l m Z m Z m Z d d l m Z m Z m Z m Z m Z d d l m  Z  d d l m! Z" d d l# Z# d   Z$ d   Z% e	 j& e j' j( d  d e f d     Y  Z) d   Z* d e+ f d     YZ, d e+ f d     YZ- d S(   s  Heuristics related to join conditions as used in
:func:`.relationship`.

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

i    (   t   absolute_importi   (   t   sqlt   utilt   exct   schemat   logi   (   t   CascadeOptionst   _orm_annotatet   _orm_deannotate(   t
   dependency(   t
   attributes(   t   ClauseAdaptert   join_conditiont   _shallow_annotatet   visit_binary_productt   _deep_deannotatet   selectables_overlap(   t	   operatorst
   expressiont   visitors(   t
   MANYTOMANYt	   MANYTOONEt	   ONETOMANYt   StrategizedPropertyt   PropComparator(   t   inspect(   t   mapperNc         C@  s   t  t j |   i t d 6 S(   s  Annotate a portion of a primaryjoin expression
    with a 'remote' annotation.

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

    .. versionadded:: 0.8

    .. seealso::

        :ref:`relationship_custom_foreign`

        :func:`.foreign`

    t   remote(   t   _annotate_columnsR   t   _clause_element_as_exprt   True(   t   expr(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR   #   s    c         C@  s   t  t j |   i t d 6 S(   s  Annotate a portion of a primaryjoin expression
    with a 'foreign' annotation.

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

    .. versionadded:: 0.8

    .. seealso::

        :ref:`relationship_custom_foreign`

        :func:`.remote`

    t   foreign(   R   R   R   R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    7   s    s   sqlalchemy.orm.propertiest   RelationshipPropertyc            B@  s  e  Z d  Z d Z e Z e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e d  Z d   Z	 d e
 f d     YZ e e d  Z e e e d  Z d   Z d	   Z e j d
  Z e d  Z d   Z e j d    Z e j e j d d  d     Z d   Z d   Z d   Z d   Z d   Z d   Z e  e e  Z! d   Z" d   Z# d   Z$ d   Z% e j d    Z& e j d    Z' e e e e e d  Z( RS(   s   Describes an object property that holds a single item or list
    of items that correspond to a related database table.

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

    See also:

    :ref:`relationship_config_toplevel`

    t   relationshipc!   !      C@  s  | |  _  | |  _ | |  _ | |  _ | |  _ |
 |  _ t |  _ | |  _ | |  _	 | |  _
 | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | p t j |  _ |  j |  t  |  _ t j  |   |  t k	 r6|  |  _! n  | rH| |  _" n |  j# d |  j	 f  |  _" t$   |  _% | t& k	 r| n d |  _' | |  _( |	 |  _) |  j) r| rt* j+ d   n  t |  _, n	 | |  _, d S(   sx  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:`.relationship`, used in a classical mapping::

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

        Some arguments accepted by :func:`.relationship` optionally accept a
        callable function, which when called produces the desired value.
        The callable is invoked by the parent :class:`.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:`.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 to import related classes at all into the local module space::

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

          :ref:`orm_tutorial_relationship` - ORM tutorial introduction.

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

          :paramref:`~.relationship.argument` 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.

          .. 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:`.Table`.
          In less common circumstances, the argument may also be specified
          as an :class:`.Alias` construct, or even a :class:`.Join` construct.

          :paramref:`~.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:`.Table` that is
          present in the :class:`.MetaData` collection associated with the
          parent-mapped :class:`.Table`.

          The :paramref:`~.relationship.secondary` keyword argument is
          typically applied in the case where the intermediary :class:`.Table`
          is not otherwise exprssed 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:`~.relationship.viewonly` flag so that this
          :func:`.relationship` is not used for persistence operations which
          may conflict with those of the association object pattern.

          .. seealso::

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

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

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

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

              :ref:`association_pattern` - an alternative to
              :paramref:`~.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:`.relationship` SQL
              conditions to be used.

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

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

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

          .. seealso::

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

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

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


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

          .. seealso::

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

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

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

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

          .. seealso::

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

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

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

          .. seealso::

            :ref:`backref_cascade` - Full discussion and examples on how
            the :paramref:`~.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.

          .. versionadded:: 0.8.3 -
             :paramref:`~.relationship.distinct_target_key` allows the
             subquery eager loader to apply a DISTINCT modifier to the
             innermost SELECT.

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

          .. seealso::

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

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

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

          .. deprecated:: 0.7 Please see :class:`.AttributeEvents`.

        :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:`.relationship`
          object's :paramref:`~.relationship.primaryjoin` condition.
          That is, if the :paramref:`~.relationship.primaryjoin`
          condition of this :func:`.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:`.relationship` is ``b.a_id``.

          In normal cases, the :paramref:`~.relationship.foreign_keys`
          parameter is **not required.** :func:`.relationship` will
          automatically determine which columns in the
          :paramref:`~.relationship.primaryjoin` conditition are to be
          considered "foreign key" columns based on those
          :class:`.Column` objects that specify :class:`.ForeignKey`,
          or are otherwise listed as referencing columns in a
          :class:`.ForeignKeyConstraint` construct.
          :paramref:`~.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:`.relationship` to consider just those columns specified
               here as "foreign".

               .. versionchanged:: 0.8
                    A multiple-foreign key join ambiguity can be resolved by
                    setting the :paramref:`~.relationship.foreign_keys`
                    parameter alone, without the need to explicitly set
                    :paramref:`~.relationship.primaryjoin` as well.

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

            3. The :paramref:`~.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:`.relationship` construct will raise informative
          error messages that suggest the use of the
          :paramref:`~.relationship.foreign_keys` parameter when
          presented with an ambiguous condition.   In typical cases,
          if :func:`.relationship` doesn't raise any exceptions, the
          :paramref:`~.relationship.foreign_keys` parameter is usually
          not needed.

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

          .. seealso::

            :ref:`relationship_foreign_keys`

            :ref:`relationship_custom_foreign`

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

          .. versionadded:: 0.8
              The :func:`.foreign` annotation can also be applied
              directly to the :paramref:`~.relationship.primaryjoin`
              expression, which is an alternate, more specific system of
              describing which columns in a particular
              :paramref:`~.relationship.primaryjoin` should be considered
              "foreign".

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

            .. versionadded:: 0.8

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

          If the joined-eager load is chained onto an existing LEFT OUTER
          JOIN, ``innerjoin=True`` will be bypassed and the join will continue
          to chain as LEFT OUTER JOIN so that the results don't change.  As an
          alternative, specify the value ``"nested"``.  This will instead nest
          the join on the right side, e.g. using the form "a LEFT OUTER JOIN
          (b JOIN c)".

          .. versionadded:: 0.9.4 Added ``innerjoin="nested"`` option to
             support nesting of eager "inner" joins.

          .. seealso::

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

            :paramref:`.joinedload.innerjoin` - loader option version

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

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

          * ``dynamic`` - the attribute will return a pre-configured
            :class:`.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` - Full documentation on relationship loader
            configuration.

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

        :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:`~.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:`~.relationship.order_by` is expected to refer to
          one of the :class:`.Column` objects to which the target class is
          mapped, or the attribute itself bound to the target class which
          refers to the column.

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

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

           .. seealso::

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

        :param passive_updates=True:
          Indicates loading and INSERT/UPDATE/DELETE behavior when the
          source of a foreign key value changes (i.e. an "on update"
          cascade), which are typically the primary key columns of the
          source row.

          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.  Note that with databases which enforce
          referential integrity (i.e. PostgreSQL, MySQL with InnoDB tables),
          ON UPDATE CASCADE is required for this operation.  The
          relationship() will update the value of the attribute on related
          items which are locally present in the session during a flush.

          When False, it is assumed that the database does not enforce
          referential integrity and will not be issuing its own CASCADE
          operation for an update.  The relationship() will issue the
          appropriate UPDATE statements to the database in response to the
          change of a referenced key, and items locally present in the
          session during a flush will also be refreshed.

          This flag should probably be set to False if primary key changes
          are expected and the database in use doesn't support CASCADE
          (i.e. SQLite, MySQL MyISAM tables).

          .. seealso::

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

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

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

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

          .. versionchanged:: 0.8
              The :func:`.remote` annotation can also be applied
              directly to the ``primaryjoin`` expression, which is an
              alternate, more specific system of describing which columns in a
              particular ``primaryjoin`` should be considered "remote".

          .. seealso::

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

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

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

          .. seealso::

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

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

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

          .. 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:`.relationship` constructs which
          are many-to-one or many-to-many and also
          specify the ``delete-orphan`` cascade option.  The
          :func:`.relationship` construct itself will raise an error
          instructing when this option is required.

          .. seealso::

            :ref:`unitofwork_cascades` - includes detail on when the
            :paramref:`~.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:`.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:`~.relationship.uselist` to
          False.

          The :paramref:`~.relationship.uselist` flag is also available on an
          existing :func:`.relationship` construct as a read-only attribute,
          which can be used to determine if this :func:`.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:`~.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:`.relationship`
          which specifies :paramref:`~.relationship.viewonly` can work
          with a wider range of SQL operations within the
          :paramref:`~.relationship.primaryjoin` condition, including
          operations that feature the use of a variety of comparison operators
          as well as SQL functions such as :func:`~.sql.expression.cast`.  The
          :paramref:`~.relationship.viewonly` flag is also of general use when
          defining any kind of :func:`~.relationship` that doesn't represent
          the full set of related objects, to prevent modifications of the
          collection from resulting in persistence operations.


        t   lazys   save-update, mergesC   backref and back_populates keyword arguments are mutually exclusiveN(-   t   uselistt   argumentt	   secondaryt   primaryjoint   secondaryjoint   post_updatet   Nonet	   directiont   viewonlyR#   t   single_parentt   _user_defined_foreign_keyst   collection_classt   passive_deletest   cascade_backrefst   passive_updatest   remote_sidet   enable_typecheckst   query_classt	   innerjoint   distinct_target_keyt   doct   active_historyt
   join_deptht   local_remote_pairst	   extensiont   load_on_pendingR!   t
   Comparatort   comparator_factoryt
   comparatorR   t   set_creation_ordert   infot   strategy_classt   _strategy_lookupt   sett   _reverse_propertyt   Falset   cascadet   order_byt   back_populatest   sa_exct   ArgumentErrort   backref(!   t   selfR%   R&   R'   R(   t   foreign_keysR$   RI   RM   RJ   R)   RH   R<   R,   R#   R/   R0   R2   R3   R4   R:   R?   R-   R6   R7   R8   R9   R1   R=   RC   t   _local_remote_pairsR5   RB   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   __init__^   s`      																														c      	   C@  s;   t  j | j |  j d |  j |  |  d | d |  j d  S(   NR@   t   parententityR8   (   R
   t   register_descriptort   class_t   keyR?   R8   (   RN   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   instrument_classG  s    	R>   c           B@  s   e  Z d  Z d Z d d d  Z d   Z e j d    Z	 e j d    Z
 d   Z d   Z d   Z d   Z d Z d	   Z d d
  Z d d  Z d d  Z d   Z d   Z d   Z e j d    Z RS(   s  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.

        See also:

        :class:`.PropComparator`

        :class:`.ColumnProperty.Comparator`

        :class:`.ColumnOperators`

        :ref:`types_operators`

        :attr:`.TypeEngine.comparator_factory`

        c         C@  s1   | |  _  | |  _ | |  _ | r- | |  _ n  d S(   s   Construction of :class:`.RelationshipProperty.Comparator`
            is internal to the ORM's attribute mechanics.

            N(   t   propt   _parentmappert   _adapt_to_entityt   _of_type(   RN   RW   t   parentmappert   adapt_to_entityt   of_type(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRQ   g  s
    			c         C@  s%   |  j  |  j |  j d | d |  j S(   NR\   R]   (   t	   __class__t   propertyRX   RZ   (   RN   R\   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR\   s  s    c         C@  s
   |  j  j S(   s   The target :class:`.Mapper` referred to by this
            :class:`.RelationshipProperty.Comparator`.

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

            (   R_   R   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR   x  s    	c         C@  s
   |  j  j S(   N(   R_   t   parent(   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _parententity  s    c         C@  s$   |  j  r |  j  j S|  j j j Sd  S(   N(   RY   t
   selectableR_   R`   t   _with_polymorphic_selectable(   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _source_selectable  s    	
c   	      C@  s   |  j    } |  j r* t |  j  j } n d  } |  j j d | d t d |  \ } } } } } } | d  k	 rw | | @S| Sd  S(   Nt   source_selectablet   source_polymorphicR]   (   Rd   RZ   R   R   R*   R_   t   _create_joinsR   (	   RN   t
   adapt_fromR]   t   pjt   sjt   sourcet   destR&   t   target_adapter(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   __clause_element__  s    	c         C@  s%   t  j |  j |  j d |  j d | S(   s   Produce a construct that represents a particular 'subtype' of
            attribute for the parent class.

            Currently this is usable in conjunction with :meth:`.Query.join`
            and :meth:`.Query.outerjoin`.

            R\   R]   (   R!   R>   R_   RX   RY   (   RN   t   cls(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR]     s
    		c         C@  s   t  d   d S(   s   Produce an IN clause - this is not implemented
            for :func:`~.orm.relationship`-based attributes at this time.

            sv   in_() not yet supported for relationships.  For a simple many-to-one, use in_() against the set of foreign key values.N(   t   NotImplementedError(   RN   t   other(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   in_  s    c         C@  s   t  | t j t j f  r` |  j j t t g k r> |  j	   St
 |  j j d d |  j  Sn= |  j j r~ t j d   n t
 |  j j | d |  j  Sd S(   s  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.

            t   adapt_sources]   Can't compare a collection to an object or collection; use contains() to test for membership.N(   t
   isinstanceR   t   NoneTypeR   t   NullR_   R+   R   R   t   _criterion_existsR   t   _optimized_compareR*   t   adapterR$   RK   t   InvalidRequestError(   RN   Rq   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   __eq__  s    %	c         K@  s,  t  |  d d   r t |  j  } | j | j | j } } } |  j j r` | r` | j	   } n  | j
 } | d  k	 r | d  k	 r | | @} q | } q n t } d  } |  j r |  j   } n d  } |  j j d t d | d |  \ }	 }
 } } } } xO | D]G } t  |  j j j |  | | k } | d  k r;| } q | | @} q W|
 d  k	 rht |	  |
 @} n t |	 d |  j j } | d  k	 r| r| r| j |  } n  | d  k	 r| j i t d 6 } n  | t j j |  @} t j d g | d | j |  } | d  k	 r(| j |  } n  | S(	   NRZ   t   dest_polymorphict   dest_selectableRe   t   excludet   no_replacement_traversei   t   from_obj(   t   getattrR*   R   RZ   R   Rb   t   is_aliased_classR_   t   _is_self_referentialt   aliast   _single_table_criterionRG   Ry   Rd   Rg   R   RT   R   R3   t   traverset	   _annotateR   t   True_t   _ifnonet   existst   correlate_except(   RN   t	   criteriont   kwargsRB   t   target_mappert   to_selectableR   t   single_critRe   Ri   Rj   Rk   Rl   R&   Rm   t   kt   critt   jt   ex(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRw     sN    		"	$c         K@  s.   |  j  j s t j d   n  |  j | |  S(   sm  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:`.relationship`
            that has ``uselist=True``.  For scalar references,
            use :meth:`~.RelationshipProperty.Comparator.has`.

            s9   'any()' not implemented for scalar attributes. Use has().(   R_   R$   RK   Rz   Rw   (   RN   R   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   any.  s    )c         K@  s.   |  j  j r t j d   n  |  j | |  S(   s  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:`.relationship`
            that has ``uselist=False``.  For collection references,
            use :meth:`~.RelationshipProperty.Comparator.any`.

            s4   'has()' not implemented for collections.  Use any().(   R_   R$   RK   Rz   Rw   (   RN   R   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   has_  s    c         K@  sd   |  j  j s t j d   n  |  j  j | d |  j } |  j  j d k	 r` |  j |  | _	 n  | S(   sd	  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.outerjoin` as well as :ref:`ormtutorial_joins`
            for more details on constructing outer joins.

            s9   'contains' not implemented for scalar attributes.  Use ==Rs   N(
   R_   R$   RK   Rz   Rx   Ry   R(   R*   t'   _Comparator__negated_contains_or_equalst   negation_clause(   RN   Rq   R   t   clause(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   contains  s    8	c      	   @  s    j  j t k r t j |  }   f d   }   f d   }   j  j r t j g    j  j D]H \ } } t j	 | |  | | |  | |  k | |  d  k  ^ q^   Sn  t j g  t   j  j j   j  j j |   D] \ } } | | k ^ q   }   j |  S(   Nc         @  s4   | j      t j |  d t d     f d   S(   Nt   uniquet	   callable_c           @  s     j  j j    S(   N(   R_   R   t   _get_committed_attr_by_column(    (   RN   t   colt   o(    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   <lambda>  s    (   t   objR   t	   bindparamR   (   t   xt   stateR   (   RN   (   R   R   sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   state_bindparam  s    c         @  s     j  r   j  |   S|  Sd  S(   N(   Ry   (   R   (   RN   (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   adapt  s    	(   R_   R+   R   R
   t   instance_statet   _use_getR   t   and_R;   t   or_R*   t   zipR   t   primary_keyt   primary_key_from_instanceRw   (   RN   Rq   R   R   R   R   t   yR   (    (   RN   sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   __negated_contains_or_equals  s    \	+c         C@  s   t  | t j t j f  rf |  j j t k rY t j	 g  |  j j
 D] } | d k ^ q@   S|  j   Sn+ |  j j r t j d   n |  j |  Sd S(   s$  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.

            s]   Can't compare a collection to an object or collection; use contains() to test for membership.N(   Rt   R   Ru   R   Rv   R_   R+   R   R   R   t   _calculated_foreign_keysR*   Rw   R$   RK   Rz   R   (   RN   Rq   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   __ne__  s    '	#c         C@  s#   t  j j r t  j j   n  |  j S(   N(   t	   mapperlibt   Mappert   _new_mapperst   _configure_allRW   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR_     s    N(   t   __name__t
   __module__t   __doc__R*   RZ   RQ   R\   R   t   memoized_propertyR   Ra   Rd   Rn   R]   Rr   t   __hash__R{   Rw   R   R   R   R   R   R_   (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR>   P  s&   					
	4B1"	E	!	5c         C@  s   | t  j k rs | d  k rW |  j r; t j d g |  j  S|  j d  d | d | Sq |  j | d | d | Sn | |  j |  Sd  S(   Ni   t   value_is_parentt   alias_secondary(	   R   t   eqR*   R$   R   R   R'   Rx   R@   (   RN   t   opt   valueR   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   compare"  s    	

c         C@  sA   | d  k	 r t j |  } n  |  j j | d | d | d | S(   Nt   reverse_directionR   Rs   (   R*   R
   R   t   _lazy_strategyt   lazy_clause(   RN   R   R   Rs   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRx   6  s    	c         C@  s   t  |  j j j  d |  j S(   Nt   .(   t   strR`   RT   R   RU   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   __str__A  s    c         C@  sJ  | r3 x* |  j  D] } | | f | k r d  Sq Wn  d |  j k rF d  S|  j | k rY d  S|  j r| j |  j  j | |  }	 t |	 d  r |	 j }	 n  | r | j |  j  j | |  n  g  }
 xv |	 D]n } t j	 |  } t j
 |  } t | | |  f <| j | | d | d | } | d  k	 r |
 j |  q q W| s~t j | | |  j  } x= |
 D] } | j |  qdWqF| j |  j  j | | |
  n | |  j } | d  k	 rt j	 |  } t j
 |  } t | | |  f <| j | | d | d | } n d  } | s$| | |  j <n" | j |  j  j | | | d   d  S(   Nt   merget   _sa_adaptert   loadt
   _recursive(   RF   t   _cascadeRU   R$   t   get_implt   gett   hasattrR   R
   R   t   instance_dictR   t   _mergeR*   t   appendt   init_state_collectiont   append_without_eventt   _set_iterableRE   (   RN   t   sessiont   source_statet   source_dictt
   dest_statet	   dest_dictR   R   t   rt	   instancest	   dest_listt   currentt   current_statet   current_dictR   t   collt   c(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR   D  sV    		c         C@  s   | j  | j } | j | | d | } | t j k sC | d k rG g  St | d  r g  | j | | | d | D] } t j |  | f ^ qr St j |  | f g Sd S(   s   Return a list of tuples (state, obj) for the given
        key.

        returns an empty list if the value is None/empty/PASSIVE_NO_RESULT
        t   passivet   get_collectionN(	   t   managert   implR   R
   t   PASSIVE_NO_RESULTR*   R   R   R   (   RN   R   t   dict_RU   R   R   R   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _value_as_iterable  s    8c      
   c@  sw  | d k s |  j  r! t j } n	 t j } | d k rX | j |  j j j | |  } n |  j | | |  j d | } | d k o d |  j	 k } x | D] \ }	 }
 |	 | k r q n  |
 d  k r q n  t j |
  } | r | |	  r q n  | r|	 j rq n  |	 j j } | j |  j j j  sQt d |  j |  j j |
 j f   n  | j |	  |
 | |	 | f Vq Wd  S(   Nt   deletes   save-updateR   s   refresh-expires   delete-orphans@   Attribute '%s' on class '%s' doesn't handle objects of type '%s'(   R0   R
   t   PASSIVE_NO_INITIALIZEt   PASSIVE_OFFR   RU   R   t   get_all_pendingR   R   R*   R   R   t   isat   class_managert   AssertionErrorR`   RT   R^   t   add(   RN   t   type_R   R   t   visited_statest   halt_onR   t   tuplest   skip_pendingR   R   R   t   instance_mapper(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   cascade_iterator  s8    			c         C@  s   |  j  j | d t } |  j j |  | j j |   | j  j |  j  sr t j d | |  | |  j f   n  |  j	 t
 t f k r |  j	 | j	 k r t j d | |  |  j	 f   n  d  S(   Nt   _configure_mappersse   reverse_property %r on relationship %s references relationship %s, which does not reference mapper %ssv   %s and back-reference %s are both of the same direction %r.  Did you mean to set remote_side on the many-to-one side ?(   R   t   get_propertyRG   RF   R   t   common_parentR`   RK   RL   R+   R   R   (   RN   RU   Rq   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _add_reverse_property  s    c         C@  s   t  j |  j  r= t |  j t t j f  r= |  j   } n	 |  j } t | t  rm t j | d t } n@ t |  j t j  r | } n" t	 j
 d |  j t |  f   | S(   s   Return the targeted :class:`.Mapper` for this
        :class:`.RelationshipProperty`.

        This is a lazy-initializing static attribute.

        t	   configuresE   relationship '%s' expects a class or a mapper argument (received: %s)(   R   t   callableR%   Rt   t   typeR   R   t   class_mapperRG   RK   RL   RU   (   RN   R%   t   mapper_(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR     s    		s   0.7s   Use .targetc         C@  s   |  j  S(   s~   Return the selectable linked to this
        :class:`.RelationshipProperty` object's target
        :class:`.Mapper`.
        (   t   target(   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   table  s    c         C@  sk   |  j    |  j   |  j   |  j |  j  |  j   |  j   t t |   j	   |  j
 d  |  _ d  S(   NR#   t   select(   s   lazyR  (   (   s   lazyR  (   t   _check_conflictst   _process_dependent_argumentst   _setup_join_conditionst   _check_cascade_settingsR   t
   _post_initt   _generate_backreft   superR!   t   do_initt   _get_strategyR   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s    




c         C@  sN  xB d
 D]: } t  |  |  } t j |  r t |  | |    q q WxN d D]F } t  |  |  } | d	 k	 rL t |  | t t j | |    qL qL W|  j t	 k	 r |  j d	 k	 r g  t j
 |  j  D] } t j | d  ^ q |  _ n  t j d   t j |  j  D  |  _ t j d   t j |  j  D  |  _ |  j j |  _ d	 S(   s   Convert incoming configuration arguments to their
        proper form.

        Callables are resolved, ORM annotations removed.

        RI   R'   R(   R&   R.   R3   c         s@  s!   |  ] } t  j | d   Vq d S(   RO   N(   R   t   _only_column_elements(   t   .0R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pys	   <genexpr>:  s   c         s@  s!   |  ] } t  j | d   Vq d S(   R3   N(   R   R  (   R  R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pys	   <genexpr>A  s   N(   s   order_bys   primaryjoins   secondaryjoins	   secondarys   _user_defined_foreign_keyss   remote_side(   s   primaryjoins   secondaryjoin(   R   R   R   t   setattrR*   R   R   R  RI   RG   t   to_listt
   column_sett   to_column_setR.   R3   R   t   mapped_tableR  (   RN   t   attrt
   attr_valuet   valR   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s,    
 
4c      !   C@  s   t  d |  j j d |  j j d |  j j d |  j j d |  j d |  j d |  j d |  j j d	 |  j j d
 |  j	 d |  j
 d |  j d |  j d |  d |  j d |  j  |  _ } | j |  _ | j |  _ | j |  _ | j
 |  _
 | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ d  S(   Nt   parent_selectablet   child_selectablet   parent_local_selectablet   child_local_selectableR'   R&   R(   t   parent_equivalentst   child_equivalentst   consider_as_foreign_keysR;   R3   t   self_referentialRW   t   support_synct   can_be_synced_fn(   t   JoinConditionR`   R  R   t   local_tableR'   R&   R(   t   _equivalent_columnsR.   R;   R3   R   R,   t   _columns_are_mappedt   _join_conditiont   deannotated_primaryjoint   deannotated_secondaryjoinR+   t   remote_columnst   local_columnst   synchronize_pairst   foreign_key_columnsR   t   secondary_synchronize_pairs(   RN   t   jc(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR  G  s4    							
c         C@  s   |  j    ri t j |  j j d t j |  j  ri t j	 d |  j |  j j j
 |  j j j
 f   n  |  j j s x^ |  j j   D]J } | |  j k	 r | j |  j  r t j d |  j |  j | f  q q Wn  d S(   sO   Test that this relationship is legal, warn about
        inheritance conflicts.R   s   Attempting to assign a new relationship '%s' to a non-primary mapper on class '%s'.  New relationships can only be added to the primary mapper, i.e. the very first mapper created for class '%s' s   Warning: relationship '%s' on mapper '%s' supersedes the same relationship on inherited mapper '%s'; this can cause dependency issues during flushN(   t
   is_primaryR   R   R`   RT   RG   t   has_propertyRU   RK   RL   R   t   concretet   iterate_to_rootR   t   warn(   RN   t
   inheriting(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR  d  s    	c         C@  s   |  j  S(   s\   Return the current cascade setting for this
        :class:`.RelationshipProperty`.
        (   R   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _get_cascade  s    c         C@  sP   t  |  } d |  j k r+ |  j |  n  | |  _ |  j rL | |  j _ n  d  S(   NR   (   R   t   __dict__R  R   t   _dependency_processorRH   (   RN   RH   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _set_cascade  s    		c      	   C@  s   | j  rG |  j rG |  j t k s1 |  j t k rG t j d |    n  |  j t k rs |  j rs t j	 d |   n  |  j d k r d | k s d | k r t j d |    n  | j  r |  j
 j   j j |  j |  j j f  n  d  S(   Ns   On %s, delete-orphan cascade is not supported on a many-to-many or many-to-one relationship when single_parent is not set.   Set single_parent=True on the relationship().sl   On %s, 'passive_deletes' is normally configured on one-to-many, one-to-one, many-to-many relationships only.t   allR   s   delete-orphans^   On %s, can't set passive_deletes='all' in conjunction with 'delete' or 'delete-orphan' cascade(   t   delete_orphanR-   R+   R   R   RK   RL   R0   R   R2  R   t   primary_mappert   _delete_orphansR   RU   R`   RT   (   RN   RH   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s$    			c         G@  sr   xk | D]c } |  j  d k	 r7 |  j  j j |  r7 q n  |  j j j j |  r |  j j j |  r t Sq Wt S(   s   Return True if all columns in the given collection are
        mapped by the tables referenced by this :class:`.Relationship`.

        N(	   R&   R*   R   t   contains_columnR`   R  R  RG   R   (   RN   t   colsR   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR$    s    c         C@  s  |  j    s d S|  j d k	 r|  j rt |  j t j  rQ |  j i  } } n |  j \ } } |  j j   } t	 | j
    j | j  } x< | D]4 } | j |  r t j d | |  | f   q q W|  j d k	 r| j d |  j j  } | j d |  j j  } nB | j d |  j j  } | j d d  } | rPt j d   n  | j d |  j  } |  j j   }	 | j d |  j  | j d |  j  | j d	 |  j  | |  _ t |	 |  j | | d | d
 |  j | }
 | j | |
  n  |  j r|  j  |  j  n  d S(   sh   Interpret the 'backref' instruction to create a
        :func:`.relationship` complementary to this one.Ns]   Error creating backref '%s' on relationship '%s': property of that name exists on mapper '%s'R'   R(   sO   Can't assign 'secondaryjoin' on a backref against a non-secondary relationship.RO   R,   R)   R2   RJ   (!   R.  RM   R*   RJ   Rt   R   t   string_typesR   R:  RE   R1  t   uniont   self_and_descendantsR/  RK   RL   R&   t   popR%  t   secondaryjoin_minus_localt   primaryjoin_minus_localt   primaryjoin_reverse_remoteRz   R.   R`   t
   setdefaultR,   R)   R2   R!   RU   t   _configure_propertyR   (   RN   t   backref_keyR   R   t   checkt   mRi   Rj   RO   R`   R"   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR	    sX    						c         C@  sI   |  j  d  k r$ |  j t k	 |  _  n  |  j sE t j j |   |  _ n  d  S(   N(	   R$   R*   R+   R   R,   R	   t   DependencyProcessort   from_relationshipR6  (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s    	c         C@  s   |  j  } | j S(   sP   memoize the 'use_get' attribute of this RelationshipLoader's
        lazyloader.(   R   t   use_get(   RN   t   strategy(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR     s    	c         C@  s   |  j  j |  j  S(   N(   R   R   R`   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR     s    c         C@  sH  | d  k r0 | r0 |  j j r0 |  j j } q0 n  t } | d  k r | ri |  j j ri |  j j } t } n |  j j } |  j r | d  k r | j	   } t } q n t } | p |  j } | j
 } | p | d  k	 } |  j j | | | |  \ }	 }
 } } } | d  k r|  j j } n  | d  k r2|  j j } n  |	 |
 | | | | f S(   N(   R*   R`   t   with_polymorphicRc   RG   R   R   R  R   R   R   R%  t   join_targetsR"  (   RN   Rf   Re   R|   R}   R]   t   aliasedt   dest_mapperR   R'   R(   R&   Rm   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRg     s0    			!	()   R   R   R   t   strategy_wildcard_keyR*   R6  RG   R   RQ   RV   R   R>   R   Rx   R   R   R
   R   R   R   R   R   R   R   t
   deprecatedR  R  R  R  R  R4  R7  R_   RH   R  R$  R	  R  R   R   Rg   (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR!   L   sx     		 			F6		
	2								B	c         @  s1      f d     |  d  k	 r-   |   }  n  |  S(   Nc         @  s>   t  |  t j  r* |  j  j    }  n  |  j d    |  S(   Nt   clone(   Rt   R   t   ColumnClauseR   t   copyt   _copy_internals(   t   elem(   RT  t   annotations(    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRT  6  s    (   R*   (   t   elementRY  (    (   RT  RY  sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR   5  s    R!  c           B@  s  e  Z d% d% d% d% d% d% d% d% e d% e d    d  Z d   Z d   Z e d    Z	 e d    Z
 e j d    Z d   Z e j d    Z e j d	    Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" e j d    Z# e j d    Z$ e j d    Z% e j d    Z& e j d     Z' d!   Z( d"   Z) d% d#  Z* e d$  Z+ RS(&   c          G@  s   t  S(   N(   R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR   R  s    c         C@  s  | |  _  | |  _ | |  _ | |  _ | |  _ |	 |  _ | |  _ | |  _ | |  _ |
 |  _	 | |  _
 | |  _ | |  _ | |  _ | |  _ | |  _ |  j   |  j   |  j   |  j   |  j   |  j |  j t  |  j d  k	 r |  j |  j t  n  |  j   |  j   |  j   d  S(   N(   R  R  R  R  R  R  R'   R(   R&   R  RP   t   _remote_sideRW   R  R  R   t   _determine_joinst   _annotate_fkst   _annotate_remotet   _annotate_localt   _setup_pairst   _check_foreign_colsR   R*   RG   t   _determine_directiont   _check_remote_sidet
   _log_joins(   RN   R  R  R  R  R'   R&   R(   R  R  R  R;   R3   R  RW   R  R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRQ   B  s6    																






c         C@  sP  |  j  d  k r d  S|  j  j } | j d |  j  |  j  | j d |  j  |  j  | j d |  j  d j d   |  j D   | j d |  j  d j d   |  j p g  D   | j d |  j  d j d	   |  j	 D   | j d
 |  j  d j d   |  j
 D   | j d |  j  d j d   |  j D   | j d |  j  |  j  d  S(   Ns   %s setup primary join %ss   %s setup secondary join %ss   %s synchronize pairs [%s]t   ,c         s@  s%   |  ] \ } } d  | | f Vq d S(   s
   (%s => %s)N(    (   R  t   lR   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pys	   <genexpr>y  s    s#   %s secondary synchronize pairs [%s]c         s@  s%   |  ] \ } } d  | | f Vq d S(   s
   (%s => %s)N(    (   R  Rf  R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pys	   <genexpr>|  s    s   %s local/remote pairs [%s]c         s@  s%   |  ] \ } } d  | | f Vq d S(   s	   (%s / %s)N(    (   R  Rf  R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pys	   <genexpr>  s    s   %s remote columns [%s]c         s@  s   |  ] } d  | Vq d S(   s   %sN(    (   R  R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pys	   <genexpr>  s    s   %s local columns [%s]c         s@  s   |  ] } d  | Vq d S(   s   %sN(    (   R  R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pys	   <genexpr>  s    s   %s relationship direction %s(   RW   R*   t   loggerRB   R'   R(   t   joinR*  R,  R;   R(  R)  R+   (   RN   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRd  p  s,    

c      	   C@  s  |  j  d k	 r7 |  j d k r7 t j d |  j   n  y |  j pF d } |  j d k	 r |  j  d k r t |  j |  j d |  j	 d | |  _  n  |  j
 d k rt |  j |  j d |  j d | |  _
 qn9 |  j
 d k rt |  j |  j d |  j d | |  _
 n  Wn t j k
 rd|  j d k	 rKt j d |  j |  j f   qt j d |  j   n[ t j k
 r|  j d k	 rt j d |  j |  j f   qt j d |  j   n Xd S(	   s   Determine the 'primaryjoin' and 'secondaryjoin' attributes,
        if not passed to the constructor already.

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

        sM   Property %s specified with secondary join condition but no secondary argumentt   a_subsetR  s1  Could not determine join condition between parent/child tables on relationship %s - there are no foreign keys linking these tables via secondary table '%s'.  Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify 'primaryjoin' and 'secondaryjoin' expressions.s  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.sl  Could not determine join condition between parent/child tables on relationship %s - there are multiple foreign key paths linking the tables via secondary table '%s'.  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.s'  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.N(   R(   R*   R&   RK   RL   RW   R  R   R  R  R'   R  R  t   NoForeignKeysErrort   AmbiguousForeignKeysError(   RN   R  (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR\    sR    							c         C@  s   t  |  j d d S(   Nt   valuest   localR   (   s   locals   remote(   R   R'   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRC    s    c         C@  s   t  |  j d d S(   NRl  Rm  R   (   s   locals   remote(   R   R(   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRB    s    c         C@  sU   |  j  r( d   } t j |  j i  |  S|  j rD t |  j d d St |  j  Sd S(   s(  Return the primaryjoin condition suitable for the
        "reverse" direction.

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

        c         S@  s|   d |  j  k r< |  j  j   } | d =t | d <|  j |  Sd |  j  k rx |  j  j   } | d =t | d <|  j |  Sd  S(   NR   Rm  (   t   _annotationsRV  R   t   _with_annotations(   RZ  t   v(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   replace  s    

Rl  Rm  R   N(   s   locals   remote(   t   _has_remote_annotationsR   t   replacement_traverseR'   t   _has_foreign_annotationsR   (   RN   Rq  (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRD    s    			c         C@  s8   x1 t  j | i   D] } | | j k r t Sq Wt Sd  S(   N(   R   t   iterateRn  R   RG   (   RN   R   t
   annotationR   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _has_annotation  s    c         C@  s   |  j  |  j d  S(   NR    (   Rw  R'   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRt    s    c         C@  s   |  j  |  j d  S(   NR   (   Rw  R'   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRr    s    c         C@  s1   |  j  r d S|  j r# |  j   n
 |  j   d S(   s   Annotate the primaryjoin and secondaryjoin
        structures with 'foreign' annotations marking columns
        considered as foreign.

        N(   Rt  R  t   _annotate_from_fk_listt   _annotate_present_fks(   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR]    s
    		c         @  s[     f d   } t  j   j i  |    _   j d  k	 rW t  j   j i  |    _ n  d  S(   Nc         @  s'   |    j  k r# |  j i t d 6 Sd  S(   NR    (   R  R   R   (   R   (   RN   (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   check_fk-  s    (   R   Rs  R'   R(   R*   (   RN   Rz  (    (   RN   sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRx  ,  s    c         @  s   |  j  d  k	 r' t j |  j  j    n	 t       f d     f d   } t j |  j i  i | d 6 |  _ |  j	 d  k	 r t j |  j	 i  i | d 6 |  _	 n  d  S(   Nc         @  s   t  |  t j  rM t  | t j  rM |  j |  r7 |  S| j |   rM | Sn    r |    k ro |   k ro |  S|   k r |    k r | Sn  d  S(   N(   Rt   R   t   Columnt
   references(   t   at   b(   t   secondarycols(    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt
   is_foreignB  s    c         @  s   t  |  j t j  s, t  |  j t j  r0 d  Sd |  j j k r d |  j j k r   |  j |  j  } | d  k	 r | j |  j  r |  j j i t	 d 6 |  _ q | j |  j  r |  j j i t	 d 6 |  _ q q n  d  S(   NR    (
   Rt   t   leftR   t   ColumnElementt   rightRn  R*   R   R   R   (   t   binaryR   (   R  (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   visit_binaryP  s    		R  (
   R&   R*   R   R  R   RE   R   t   cloned_traverseR'   R(   (   RN   R  (    (   R  R  sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRy  <  s    	c         @  sU   |  j    |  j  t g      f d   } t j |  j i  i | d 6  d S(   sv   Return True if the join condition contains column
        comparisons where both columns are in both tables.

        c         @  s   |  j  |  j } } t | t j  r t | t j  r   j | j  r   j | j  r  j | j  r  j | j  r t  d <n  d  S(   Ni    (   R  R  Rt   R   RU  t   is_derived_fromR  R   (   R  R   t   f(   t   ptt   mtt   result(    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR  u  s    R  i    (   R  R  RG   R   R   R'   (   RN   R  (    (   R  R  R  sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _refers_to_parent_tablel  s    			c         C@  s   t  |  j |  j  S(   s5   Return True if parent/child tables have some overlap.(   R   R  R  (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _tables_overlap  s    c         C@  s   |  j  r d S|  j d k	 r) |  j   nd |  j s; |  j rH |  j   nE |  j   rj |  j d   t	  n# |  j
   r |  j   n
 |  j   d S(   s   Annotate the primaryjoin and secondaryjoin
        structures with 'remote' annotations marking columns
        considered as part of the 'remote' side.

        Nc         S@  s   d |  j  k S(   NR    (   Rn  (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR     s    (   Rr  R&   R*   t   _annotate_remote_secondaryRP   R[  t   _annotate_remote_from_argsR  t   _annotate_selfrefRG   R  t   _annotate_remote_with_overlapt%   _annotate_remote_distinct_selectables(   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR^    s    	c         @  sI     f d   } t  j   j i  |    _ t  j   j i  |    _ d S(   s^   annotate 'remote' in primaryjoin, secondaryjoin
        when 'secondary' is present.

        c         @  s-     j  j j |   r) |  j i t d 6 Sd  S(   NR   (   R&   R   R<  R   R   (   RZ  (   RN   (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   repl  s    N(   R   Rs  R'   R(   (   RN   R  (    (   RN   sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s
    c         @  s;       f d   } t  j   j i  i | d 6   _ d S(   sx   annotate 'remote' in primaryjoin, secondaryjoin
        when the relationship is detected as self-referential.

        c         @  s   |  j  j |  j  } t |  j  t j  r t |  j t j  r  |  j   rm |  j  j i t d 6 |  _  n   |  j  r | r |  j j i t d 6 |  _ q n  s   j   n  d  S(   NR   (	   R  R   R  Rt   R   RU  R   R   t   _warn_non_column_elements(   R  t   equated(   RN   t   remote_side_givent   fn(    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s    	R  N(   R   R  R'   (   RN   R  R  R  (    (   RN   R  R  sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s    	c         @  s   |  j  rI |  j r$ t j d   n  g  |  j  D] \ } } | ^ q.   n	 |  j   |  j   rz |  j   f d   t  n*   f d   } t j |  j	 i  |  |  _	 d S(   s   annotate 'remote' in primaryjoin, secondaryjoin
        when the 'remote_side' or '_local_remote_pairs'
        arguments are used.

        sT   remote_side argument is redundant against more detailed _local_remote_side argument.c         @  s
   |    k S(   N(    (   R   (   R3   (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR     s    c         @  s$   |    k r  |  j  i t d 6 Sd  S(   NR   (   R   R   (   RZ  (   R3   (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s    N(
   RP   R[  RK   RL   R  R  R   R   Rs  R'   (   RN   Rf  R   R  (    (   R3   sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s    		%	c         @  sD     f d   }  f d     t  j  j i  i | d 6  _ d S(   s   annotate 'remote' in primaryjoin, secondaryjoin
        when the parent/child tables have some set of
        tables in common, though is not a fully self-referential
        relationship.

        c         @  sF     |  j  |  j  \ |  _  |  _   |  j |  j   \ |  _ |  _  d  S(   N(   R  R  (   R  (   t   proc_left_right(    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s    		c         @  s~   t  |  t j  rj t  | t j  rj   j j j |  rt   j j j |   rt | j i t d 6 } qt n
   j	   |  | f S(   NR   (
   Rt   R   RU  R  R   R<  R  R   R   R  (   R  R  (   RN   (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s    
R  N(   R   R  R'   (   RN   R  (    (   R  RN   sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s
    	c         @  s.     f d   } t  j   j i  |    _ d S(   s}   annotate 'remote' in primaryjoin, secondaryjoin
        when the parent/child tables are entirely
        separate.

        c         @  sX     j  j j |   rT   j j j |   s@   j j j |   rT |  j i t d 6 Sd  S(   NR   (   R  R   R<  R  R  R   R   (   RZ  (   RN   (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR   	  s    
	N(   R   Rs  R'   (   RN   R  (    (   RN   sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR    s    c         C@  s   t  j d |  j  d  S(   Ns   Non-simple column elements in primary join condition for property %s - consider using remote() annotations to mark the remote side.(   R   R2  RW   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR  
	  s    c         @  s   |  j  |  j d  r d S|  j rP t j g  |  j D] \ } } | ^ q2    n t j |  j j      f d   } t j |  j i  |  |  _ d S(   sC  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.

        Rm  Nc         @  s3   d |  j  k r/ |    k r/ |  j i t d 6 Sd  S(   NR   Rm  (   Rn  R   R   (   RX  (   t
   local_side(    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   locals_&	  s    (	   Rw  R'   RP   R   R  R  R   R   Rs  (   RN   Rf  R   R  (    (   R  sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR_  	  s    		%c         C@  s)   |  j  s% t j d |  j f   n  d  S(   Ns  Relationship %s 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.(   R;   RK   RL   RW   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRc  .	  s    	c         C@  s  t  } |  j | d  } t |  } | r< t |  j  } n t |  j  } |  j rZ | sj |  j rn | rn d S|  j r | r | r d | r d p d | |  j f } | d 7} t j |   n; d | r d p d | |  j f } | d 7} t j |   d S(	   sH   Check the foreign key columns collected and emit error
        messages.R    Ns   Could not locate any simple equality expressions involving locally mapped foreign key columns for %s join condition '%s' on relationship %s.t   primaryR&   s    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.s`   Could not locate any relevant foreign key columns for %s join condition '%s' on relationship %s.s     Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or are annotated in the join condition with the foreign() annotation.(	   RG   t   _gather_columns_with_annotationt   boolR*  R,  R  RW   RK   RL   (   RN   R   R  t   can_synct   foreign_colst   has_foreignt   err(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRa  :	  s2    c   	      C@  s  |  j  d k	 r t |  _ nvt j |  j j  } t j |  j j  } | j	 |  j
  } | j	 |  j
  } | rW| rW|  j |  j d d  } t g  |  j |  j d  D] } d | j k r | ^ q  } | r| r|  j j	 |  j  } | j |  } | j |  } n  | r%| r%t |  _ q| r>| r>t |  _ qt j d |  j   n: | rit |  _ n( | r{t |  _ n t j d |  j   d S(   s[   Determine if this relationship is one to many, many to one,
        many to many.

        R   R    sD  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.s   Can't determine relationship direction for relationship '%s' - foreign key columns are present in neither the parent nor the child's mapped tablesN(   R(   R*   R   R+   R   R  R  R   R  t   intersectionR+  R  R'   RE   Rn  R(  R)  t
   differenceR   R   RK   RL   RW   (	   RN   t
   parentcolst
   targetcolst   onetomany_fkt   manytoone_fkt   onetomany_localR   t   manytoone_localt   self_equated(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRb  p	  sF    		c         C@  s/   g  | D]$ \ } } | j    | j    f ^ q S(   s   provide deannotation for the various lists of
        pairs, so that using them in hashes doesn't incur
        high-overhead __eq__() comparisons against
        original columns mapped.

        (   t   _deannotate(   RN   t
   collectionR   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   _deannotate_pairs	  s    c         @  s   g  } t  j g    g  }    f d   } xK   j | f   j | f g D]+ \ } } | d  k rj qL n  | | |  qL W  j     _   j |    _   j |    _ d  S(   Nc         @  s&       f d   } t  | |   d  S(   Nc         @  s   d | j  k rC d | j  k rC   j |  rC  j | | f  nC d | j  k r d | j  k r   j |  r  j | | f  n  |  j t j k r   j | |  r d | j  k r  j | | f  q d | j  k r  j | | f  q n  d  S(   NR   R    (   Rn  R   R   t   operatorR   R   R   (   R  R  R  (   RN   R  t   lrp(    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR  	  s    (   R   (   t   joincondR  R  (   RN   R  (   R  sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   go	  s    (	   R   t
   OrderedSetR'   R(   R*   R  R;   R*  R,  (   RN   t
   sync_pairst   secondary_sync_pairsR  R  R  (    (   RN   R  sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR`  	  s    c         C@  s   |  j  d  S(   NR   (   t   _gather_join_annotations(   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR(  	  s    c         C@  s   |  j  d  S(   NRm  (   R  (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR)  	  s    c         C@  s   |  j  d  S(   NR    (   R  (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR+  	  s    c         C@  s   t  |  j  S(   N(   R   R'   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR&  	  s    c         C@  s$   |  j  d  k	 r t |  j   Sd  Sd  S(   N(   R(   R*   R   (   RN   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR'  	  s    c         C@  sl   t  |  j |  j |   } |  j d  k	 rI | j |  j |  j |   n  t  g  | D] } | j   ^ qS  S(   N(   RE   R  R'   R(   R*   t   updateR  (   RN   Rv  t   sR   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR  
  s    c         G@  sG   t  |  } t  g  t j | i   D] } | j | j  r" | ^ q"  S(   N(   RE   R   Ru  t   issubsetRn  (   RN   R   Rv  R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR  
  s    c         C@  s  t  | i t d 6 } |  j |  j |  j } } } | d k	 re | d k	 rX | | @} qe | | @} n  | r}| d k	 r | j d t  } t |  } t | d |  j j	 |  }	 | d k	 r t |  j	 t | d |  j
  } n  |	 j |  } n^ t | d t d  d |  j } | d k	 rP| j	 t | d t d  d |  j
  n  d }	 | j |  } |	 pn| }
 d |
 _ n d }
 | | | |
 | f S(   s7  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   t   flatt   equivalentst
   exclude_fnRm  R   N(   R   R   R'   R(   R&   R*   R   R   R  t   chainR  R   t   _ColInAnnotationsR  (   RN   Re   R}   RP  R   R'   R(   R&   t   primary_aliasizert   secondary_aliasizerRm   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRO  
  sL    				c   	      @  s  t  j    t j t   t  j   }   rz |  j d  k rz xv |  j D]- \ } }  | j | | f  | | | <qF Wn; x8 |  j D]- \ } }  | j | | f  | | | <q W    f d   } |  j	 } |  j d  k s   rt
 j | i  |  } n  |  j d  k	 rL|  j }   r7t
 j | i  |  } n  t j | |  } n  t  f d    D  } t |  } | | | f S(   Nc      
   @  s     r |   k s(   r d |  j  k r |   k rb x+  |  D] \ } } |  k r? d  Sq? Wn  |   k r t j d  d  d |  j d t  |  <n   |  Sd  S(   NRm  R   R   (   Rn  R*   R   R   R   R   (   R   t   tobindR  (   R   t   bindst   lookup(    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   col_to_bindo
  s    "c         3@  s"   |  ] }   | j  | f Vq d  S(   N(   RU   (   R  R   (   R  (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pys	   <genexpr>
  s    (   R   t   column_dictt   collectionst   defaultdictt   listR(   R*   R;   R   R'   R   Rs  R   R   t   dictR   (	   RN   R   t   equated_columnsRf  R   R  t	   lazywhereR(   t   bind_to_col(    (   R   R  R  sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   create_lazy_clause_
  s0    		N(,   R   R   R*   RG   R   RQ   Rd  R\  R_   RC  RB  R   R   RD  Rw  Rt  Rr  R]  Rx  Ry  R  R  R^  R  R  R  R  R  R  R_  Rc  Ra  Rb  R  R`  R(  R)  R+  R&  R'  R  R  RO  R  (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR!  A  s^   		[!				0												6	O	
	$		
ER  c           B@  s    e  Z d  Z d   Z d   Z RS(   sK   Seralizable equivalent to:

        lambda c: "name" in c._annotations
    c         C@  s   | |  _  d  S(   N(   t   name(   RN   R  (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyRQ   
  s    c         C@  s   |  j  | j k S(   N(   R  Rn  (   RN   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   __call__
  s    (   R   R   R   RQ   R  (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyR  
  s   	(.   R   t
   __future__R    t    R   R   R   RK   R   R   R   R   R   R	   R
   t   sql.utilR   R   R   R   R   R   R   R   R   t
   interfacesR   R   R   R   R   t
   inspectionR   R   R   R  R   R    t   class_loggert   langhelperst   dependency_forR!   R   t   objectR!  R  (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/relationships.pyt   <module>   s8   (.(		      	   R