ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ 4]c@@spdZddlmZddlZddlZddlmZddlmZddlmZ ddl m Z dd l m Z dd l mZdd l mZdd l mZdd l mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl m#Z#ddl m$Z$ddl m%Z%dd l m&Z&dd!l m'Z'd"Z(d#Z)ej*ej+j,d$d%e-d&efd'YZ.d(Z/d)e0fd*YZ1d+e0fd,YZ2dS(-sHeuristics 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(tabsolute_importNi(t attributes(t dependency(tmapper(t state_str(t MANYTOMANY(t MANYTOONE(t ONETOMANY(tPropComparator(tStrategizedProperty(t _orm_annotate(t_orm_deannotate(tCascadeOptionsi(texc(tlog(tschema(tsql(tutil(tinspect(t expression(t operators(tvisitors(t_deep_deannotate(t_shallow_annotate(tadapt_criterion_to_null(t ClauseAdapter(tjoin_condition(tselectables_overlap(tvisit_binary_productcC@sttj|itd6S(sAnnotate a portion of a primaryjoin expression with a 'remote' annotation. See the section :ref:`relationship_custom_foreign` for a description of use. .. seealso:: :ref:`relationship_custom_foreign` :func:`.foreign` tremote(t_annotate_columnsRt_clause_element_as_exprtTrue(texpr((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR3scC@sttj|itd6S(sAnnotate a portion of a primaryjoin expression with a 'foreign' annotation. See the section :ref:`relationship_custom_foreign` for a description of use. .. seealso:: :ref:`relationship_custom_foreign` :func:`.remote` tforeign(RRRR (R!((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR"Fsssqlalchemy.orm.propertiest add_to_alltRelationshipPropertyc"B@seZdZdZeZejdddfeeeeeeeeeeeedeee ee eeeeeeee ee eeeed Z dZ de fd YZ e ed Zeee d Zd Zeed ZdZdZejdZedZdZejdZejdZdZdZdZdZdZ dZ!e"e e!Z#dZ$dZ%dZ&dZ'dZ(ejd Z)ejd!Z*eeeeed"Z+RS(#sDescribes an object property that holds a single item or list of items that correspond to a related database table. Public constructor is the :func:`.orm.relationship` function. .. seealso:: :ref:`relationship_config_toplevel` t relationshipt extensions0.7s:class:`.AttributeExtension` is deprecated in favor of the :class:`.AttributeEvents` listener interface. The :paramref:`.relationship.extension` parameter will be removed in a future release.tselectc""C@stt|j||_||_||_||_||_| |_t |_ | |_ ||_ ||_ ||_||_||_||_||_||_||_||_||_||_||_||_||_|!|_||_| |_||_||_|ptj |_!|j!|t |_"t#j$|| t k r[| |_%nd|j ff|_&t'|_(| t)k r| nd|_*||_+| |_,|j,r|rt-j.dnt |_/n ||_/dS(s}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 for related classes to be imported into the local module space before the dependent classes have been declared. It is still required that the modules in which these related classes appear are imported anywhere in the application at some point before the related mappings are actually used, else a lookup error will be raised when the :func:`.relationship` attempts to resolve the string reference to the related class. An example of a string- resolved class is as follows:: from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) children = relationship("Child", order_by="Child.id") .. seealso:: :ref:`relationship_config_toplevel` - Full introductory and reference documentation for :func:`.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 expressed in any direct class mapping. If the "secondary" table is also explicitly mapped elsewhere (e.g. as in :ref:`association_pattern`), one should consider applying the :paramref:`~.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 bake_queries=True: Use the :class:`.BakedQuery` cache to cache the construction of SQL used in lazy loads. True by default. Set to False if the join condition of the relationship has unusual features that might not respond well to statement caching. .. versionchanged:: 1.2 "Baked" loading is the default implementation for the "select", a.k.a. "lazy" loading strategy for relationships. .. versionadded:: 1.0.0 .. seealso:: :ref:`baked_toplevel` :param cascade: a comma-separated list of cascade rules which determines how Session operations should be "cascaded" from parent to child. This defaults to ``False``, which means the default cascade should be used - this default cascade is ``"save-update, merge"``. The available cascades are ``save-update``, ``merge``, ``expunge``, ``delete``, ``delete-orphan``, and ``refresh-expire``. An additional option, ``all`` indicates shorthand for ``"save-update, merge, refresh-expire, expunge, delete"``, and is often used as in ``"all, delete-orphan"`` to indicate that related objects should follow along with the parent object in all cases, and be deleted when de-associated. .. seealso:: :ref:`unitofwork_cascades` - Full detail on each of the available cascade options. :ref:`tutorial_delete_cascade` - Tutorial example describing a delete cascade. :param cascade_backrefs=True: a boolean value indicating if the ``save-update`` cascade should operate along an assignment event intercepted by a backref. When set to ``False``, the attribute managed by this relationship will not cascade an incoming transient object into the session of a persistent parent, if the event is received via backref. .. seealso:: :ref:`backref_cascade` - Full discussion and examples on how the :paramref:`~.relationship.cascade_backrefs` option is used. :param collection_class: a class or callable that returns a new list-holding object. will be used in place of a plain list for storing elements. .. seealso:: :ref:`custom_collections` - Introductory documentation and examples. :param comparator_factory: a class which extends :class:`.RelationshipProperty.Comparator` which provides custom SQL clause generation for comparison operations. .. seealso:: :class:`.PropComparator` - some detail on redefining comparators at this level. :ref:`custom_comparators` - Brief intro to this feature. :param distinct_target_key=None: Indicate if a "subquery" eager load should apply the DISTINCT keyword to the innermost SELECT statement. When left as ``None``, the DISTINCT keyword will be applied in those cases when the target columns do not comprise the full primary key of the target table. When set to ``True``, the DISTINCT keyword is applied to the innermost SELECT unconditionally. It may be desirable to set this flag to False when the DISTINCT is reducing performance of the innermost subquery beyond that of what duplicate innermost rows may be causing. .. versionchanged:: 0.9.0 - :paramref:`~.relationship.distinct_target_key` now defaults to ``None``, so that the feature enables itself automatically for those cases where the innermost query targets a non-unique key. .. seealso:: :ref:`loading_toplevel` - includes an introduction to subquery eager loading. :param doc: docstring which will be applied to the resulting descriptor. :param extension: an :class:`.AttributeExtension` instance, or list of extensions, which will be prepended to the list of attribute listeners for the resulting descriptor placed on the class. :param foreign_keys: a list of columns which are to be used as "foreign key" columns, or columns which refer to the value in a remote column, within the context of this :func:`.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` condition 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". 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. :param info: Optional data dictionary which will be populated into the :attr:`.MapperProperty.info` attribute of this object. :param innerjoin=False: when ``True``, joined eager loads will use an inner join to join against related tables instead of an outer join. The purpose of this option is generally one of performance, as inner joins generally perform better than outer joins. This flag can be set to ``True`` when the relationship references an object via many-to-one using local foreign keys that are not nullable, or when the reference is one-to-one or a collection that is guaranteed to have one or at least one entry. The option supports the same "nested" and "unnested" options as that of :paramref:`.joinedload.innerjoin`. See that flag for details on nested / unnested behaviors. .. seealso:: :paramref:`.joinedload.innerjoin` - the option as specified by loader option, including detail on nesting behavior. :ref:`what_kind_of_loading` - Discussion of some details of various loader options. :param join_depth: when non-``None``, an integer value indicating how many levels deep "eager" loaders should join on a self-referring or cyclical relationship. The number counts how many times the same Mapper shall be present in the loading condition along a particular join branch. When left at its default of ``None``, eager loaders will stop chaining when they encounter a the same target mapper which is already higher up in the chain. This option applies both to joined- and subquery- eager loaders. .. seealso:: :ref:`self_referential_eager_loading` - Introductory documentation and examples. :param lazy='select': specifies how the related items should be loaded. Default value is ``select``. Values include: * ``select`` - items should be loaded lazily when the property is first accessed, using a separate SELECT statement, or identity map fetch for simple many-to-one references. * ``immediate`` - items should be loaded as the parents are loaded, using a separate SELECT statement, or identity map fetch for simple many-to-one references. * ``joined`` - items should be loaded "eagerly" in the same query as that of the parent, using a JOIN or LEFT OUTER JOIN. Whether the join is "outer" or not is determined by the :paramref:`~.relationship.innerjoin` parameter. * ``subquery`` - items should be loaded "eagerly" as the parents are loaded, using one additional SQL statement, which issues a JOIN to a subquery of the original statement, for each collection requested. * ``selectin`` - items should be loaded "eagerly" as the parents are loaded, using one or more additional SQL statements, which issues a JOIN to the immediate parent object, specifying primary key identifiers using an IN clause. .. versionadded:: 1.2 * ``noload`` - no loading should occur at any time. This is to support "write-only" attributes, or attributes which are populated in some manner specific to the application. * ``raise`` - lazy loading is disallowed; accessing the attribute, if its value were not already loaded via eager loading, will raise an :exc:`~sqlalchemy.exc.InvalidRequestError`. This strategy can be used when objects are to be detached from their attached :class:`.Session` after they are loaded. .. versionadded:: 1.1 * ``raise_on_sql`` - lazy loading that emits SQL is disallowed; accessing the attribute, if its value were not already loaded via eager loading, will raise an :exc:`~sqlalchemy.exc.InvalidRequestError`, **if the lazy load needs to emit SQL**. If the lazy load can pull the related value from the identity map or determine that it should be None, the value is loaded. This strategy can be used when objects will remain associated with the attached :class:`.Session`, however additional SELECT statements should be blocked. .. versionadded:: 1.1 * ``dynamic`` - the attribute will return a pre-configured :class:`.Query` object for all read operations, onto which further filtering operations can be applied before iterating the results. See the section :ref:`dynamic_relationship` for more details. * True - a synonym for 'select' * False - a synonym for 'joined' * None - a synonym for 'noload' .. seealso:: :doc:`/orm/loading_relationships` - Full documentation on relationship loader configuration. :ref:`dynamic_relationship` - detail on the ``dynamic`` option. :ref:`collections_noload_raiseload` - notes on "noload" and "raise" :param load_on_pending=False: Indicates loading behavior for transient or pending parent objects. When set to ``True``, causes the lazy-loader to issue a query for a parent object that is not persistent, meaning it has never been flushed. This may take effect for a pending object when autoflush is disabled, or for a transient object that has been "attached" to a :class:`.Session` but is not part of its pending collection. The :paramref:`~.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 rule is in place which will handle updating/deleting child rows on the database side. Additionally, setting the flag to the string value 'all' will disable the "nulling out" of the child foreign keys, when the parent object is deleted and there is no delete or delete-orphan cascade enabled. This is typically used when a triggering or error raise scenario is in place on the database side. Note that the foreign key attributes on in-session child objects will not be changed after a flush occurs so this is a very special use-case setting. Additionally, the "nulling out" will still occur if the child object is de-associated with the parent. .. seealso:: :ref:`passive_deletes` - Introductory documentation and examples. :param passive_updates=True: Indicates the persistence behavior to take when a referenced primary key value changes in place, indicating that the referencing foreign key columns will also need their value changed. When True, it is assumed that ``ON UPDATE CASCADE`` is configured on the foreign key in the database, and that the database will handle propagation of an UPDATE from a source column to dependent rows. When False, the SQLAlchemy :func:`.relationship` construct will attempt to emit its own UPDATE statements to modify related targets. However note that SQLAlchemy **cannot** emit an UPDATE for more than one level of cascade. Also, setting this flag to False is not compatible in the case where the database is in fact enforcing referential integrity, unless those constraints are explicitly "deferred", if the target backend supports it. It is highly advised that an application which is employing mutable primary keys keeps ``passive_updates`` set to True, and instead uses the referential integrity features of the database itself in order to handle the change efficiently and fully. .. seealso:: :ref:`passive_updates` - Introductory documentation and examples. :paramref:`.mapper.passive_updates` - a similar flag which takes effect for joined-table inheritance mappings. :param post_update: this indicates that the relationship should be handled by a second UPDATE statement after an INSERT or before a DELETE. Currently, it also will issue an UPDATE after the instance was UPDATEd as well, although this technically should be improved. This flag is used to handle saving bi-directional dependencies between two individual rows (i.e. each row references the other), where it would otherwise be impossible to INSERT or DELETE both rows fully since one row exists before the other. Use this flag when a particular mapping arrangement will incur two rows that are dependent on each other, such as a table that has a one-to-many relationship to a set of child rows, and also has a column that references a single child row within that list (i.e. both tables contain a foreign key to each other). If a flush operation returns an error that a "cyclical dependency" was detected, this is a cue that you might want to use :paramref:`~.relationship.post_update` to "break" the cycle. .. seealso:: :ref:`post_update` - Introductory documentation and examples. :param primaryjoin: a SQL expression that will be used as the primary join of the child object against the parent object, or in a many-to-many relationship the join of the parent object to the association table. By default, this value is computed based on the foreign key relationships of the parent and child tables (or association table). :paramref:`~.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. .. 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. :param omit_join: Allows manual control over the "selectin" automatic join optimization. Set to ``False`` to disable the "omit join" feature added in SQLAlchemy 1.3. .. versionadded:: 1.3 tlazyssave-update, mergesCbackref and back_populates keyword arguments are mutually exclusiveN(0tsuperR$t__init__tuselisttargumentt secondaryt primaryjoint secondaryjoint post_updatetNonet directiontviewonlyR(t single_parentt_user_defined_foreign_keystcollection_classtpassive_deletestcascade_backrefstpassive_updatest remote_sidetenable_typecheckst query_classt innerjointdistinct_target_keytdoctactive_historyt join_deptht omit_jointlocal_remote_pairsR&t bake_queriestload_on_pendingt Comparatortcomparator_factoryt comparatorRtset_creation_ordertinfot strategy_keytsett_reverse_propertytFalsetcascadetorder_bytback_populatestsa_exct ArgumentErrortbackref("tselfR,R-R.R/t foreign_keysR+RPRTRQR0ROR&R3R(R6R7R9R:R;RARGR4R=R>R?R@R8RERDt_local_remote_pairsR<RJRB((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR*ls^                                     c C@s;tj|j|jd|j||d|d|jdS(NRHt parententityR?(Rtregister_descriptortclass_tkeyRGR?(RUR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytinstrument_classs  RFcB@seZdZdZdddZdZejdZ ejdZ ejdZ dZ dZ dZd ZdZd Zdd Zdd Zdd ZdZdZdZejdZRS(sProduce boolean, comparison, and other operators for :class:`.RelationshipProperty` attributes. See the documentation for :class:`.PropComparator` for a brief overview of ORM level operator definition. .. seealso:: :class:`.PropComparator` :class:`.ColumnProperty.Comparator` :class:`.ColumnOperators` :ref:`types_operators` :attr:`.TypeEngine.comparator_factory` cC@s1||_||_||_|r-||_ndS(sConstruction of :class:`.RelationshipProperty.Comparator` is internal to the ORM's attribute mechanics. N(tpropt _parententityt_adapt_to_entityt_of_type(RUR]t parentmappertadapt_to_entitytof_type((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR*s    cC@s%|j|j|jd|d|jS(NRbRc(t __class__tpropertyR^R`(RURb((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRbs  cC@s |jjS(s#The target entity referred to by this :class:`.RelationshipProperty.Comparator`. This is either a :class:`.Mapper` or :class:`.AliasedInsp` object. This is the "target" or "remote" side of the :func:`.relationship`. (Retentity(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRfs cC@s |jjS(sThe target :class:`.Mapper` referred to by this :class:`.RelationshipProperty.Comparator`. This is the "target" or "remote" side of the :func:`.relationship`. (ReR(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRs cC@s |jjS(N(Retparent(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR^scC@s$|jr|jjS|jjjSdS(N(R_t selectableReRgt_with_polymorphic_selectable(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt_source_selectables  c C@s|j}|jr*t|jj}nd}|jjd|dtd|\}}}}}}|dk rw||@S|SdS(Ntsource_selectabletsource_polymorphictof_type_mapper(RjR`RRR1Ret _create_joinsR ( RUt adapt_fromRmtpjtsjtsourcetdestR-ttarget_adapter((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt__clause_element__s    cC@s%tj|j|jd|jd|S(sRedefine this object in terms of a polymorphic subclass. See :meth:`.PropComparator.of_type` for an example. RbRc(R$RFReR^R_(RUtcls((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRcs   cC@stddS(sProduce an IN clause - this is not implemented for :func:`~.orm.relationship`-based attributes at this time. svin_() not yet supported for relationships. For a simple many-to-one, use in_() against the set of foreign key values.N(tNotImplementedError(RUtother((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytin_scC@st|tjtjfr`|jjttgkr>|j St |jj dd|j Sn=|jjr~tjdnt |jj |d|j SdS(sImplement the ``==`` operator. In a many-to-one context, such as:: MyClass.some_prop == this will typically produce a clause such as:: mytable.related_id == Where ```` 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 isinstanceRtNoneTypeRtNullReR2RRt_criterion_existsR t_optimized_compareR1tadapterR+RRtInvalidRequestError(RURx((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt__eq__s%     cK@sJt|ddrt|j}|j|j|j}}}|jjr`| r`|j }n|j }|dk r|dk r||@}q|}qn t }d}|j r|j }nd}|jjdtd|d|\} } } } } }xO|D]G}t|jjj|||k}|dkr;|}q||@}qW| dk rht| | @}nt| d|jj}|dk r|r| r|j|}n|dk r|jitd6}n|tjj|@}| dk r"tjdg|d| | gj| | }n$tjdg|d| j| }|S( NR`tdest_polymorphictdest_selectableRktexcludetno_replacement_traverseitfrom_obj(tgetattrR1RR`RRhtis_aliased_classRet_is_self_referentialtaliast_single_table_criterionRNRRjRnR RZR R:ttraverset _annotateRtTrue_t_ifnonetexiststcorrelate_except(RUt criteriontkwargsRJt target_mappert to_selectableRt single_critRkRpRqRrRsR-Rttktcrittjtex((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR~IsX        "       cK@s.|jjstjdn|j||S(smProduce 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().(ReR+RRRR~(RURR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytanys)  cK@s.|jjrtjdn|j||S(sProduce 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().(ReR+RRRR~(RURR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pythass  cK@sd|jjstjdn|jj|d|j}|jjdk 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 == Where ```` 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 = Where ```` 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 ==RzN( ReR+RRRRRR/R1t'_Comparator__negated_contains_or_equalstnegation_clause(RURxRtclause((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytcontainss8   c @s jjtkrtj|}fd}fd}jjrtjgjjD]H\}}tj |||||||k||dk^q^Sntjgt jj j jj j|D]\}}||k^q}j|S(Nc @s=|j}tj|dtdjjjj|||S(Ntuniquet callable_(tdictRt bindparamR Ret_get_attr_w_warn_on_noneR(txtstatetcoltdict_(RU(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytstate_bindparam<s   c@sjrj|S|SdS(N(R(R(RU(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytadaptFs  (ReR2RRtinstance_statet_use_getRtand_RCtor_R1tzipRt primary_keytprimary_key_from_instanceR~(RURxRRRRtyR((RUsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt__negated_contains_or_equals8s  \ 7cC@st|tjtjfrZ|jjtkrMt|jj dd|j S|j Sn1|jj rxtjdnt|j|SdS(s$Implement the ``!=`` operator. In a many-to-one context, such as:: MyClass.some_prop != This will typically produce a clause such as:: mytable.related_id != Where ```` 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. Rzs]Can't compare a collection to an object or collection; use contains() to test for membership.N(R{RR|RR}ReR2RR RR1RR~R+RRRR(RURx((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt__ne__ds'    cC@s#tjjrtjjn|jS(N(t mapperlibtMappert _new_mapperst_configure_allR](RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRes N(t__name__t __module__t__doc__R1R`R*RbRtmemoized_propertyRfRR^RjRuRcRyt__hash__RR~RRRRRRe(((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRFs(      : T 1 " H , :cC@sj|dk std}|dk rKt|}|jrK|jj}qKn|j|dtd|d|S(Ntvalue_is_parentRztalias_secondary(R1tAssertionErrorRRt_adaptert adapt_clauseRR (RUtinstanceRt from_entityRztinsp((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt _with_parents   c@s5dk rtjn| }dkrDj|d|S|sfjjjj}njjjj}|rj n j tj j fd}j dk r|rtj jj|}ntj|ii|d6}|r1||}n|S(NRzc@s8|jkr4j|j|_ndS(N(t_identifying_keyRtcallable(R(t bind_to_colRRRUR(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytvisit_bindparams R(R1RRt_lazy_none_clauset_lazy_strategyt _lazywheret _bind_to_colt_rev_lazywheret_rev_bind_to_colRRgt instance_dicttobjR-RRRRtcloned_traverse(RURRRzRtreverse_directionRR((RRRRURsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRs0         c@s>jjjfd}|S(sKCreate the callable that is used in a many-to-one expression. E.g.:: u1 = s.query(User).get(5) expr = Address.user == u1 Above, the SQL should be "address.user_id = 5". The callable returned by this method produces the value "5" based on the identity of ``u1``. c@sjj}}|tjk }jdjrGtjn tjtjA}|tj kr|st j dt fqn@|tj kr|st j dt fqn|}|dkrtjdn|S(NtpassivesUCan't resolve value for column %s on object %s; no value has been set for this columns`Can't resolve value for column %s on object %s; the object is detached and the value was expiredsGot None for value of column %s; this is unsupported for a relationship comparison and will not currently produce an IS comparison (but may in a future release)(t_last_known_valuesR[RtNO_VALUEt_get_state_attr_by_columnt persistentt PASSIVE_OFFtPASSIVE_NO_FETCHtINIT_OKt NEVER_SETRRRRtPASSIVE_NO_RESULTR1Rtwarn(t last_knownt to_returntexisting_is_availablet current_value(tcolumnRRR]R(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt_gos0  (tget_property_by_columnt_track_last_known_valueR[(RURRRRR((RRRR]RsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRs+*cC@sc|s"|jj|jj}}n|jj|jj}}t||}|r_||}n|S(N(RRRRRR(RURRzRR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRIs  cC@st|jjjd|jS(Nt.(tstrRgRZRR[(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt__str__[sc  C@s\|r3x*|jD]} || f|krdSqWnd|jkrFdS|j|krYdS|jr|j|jj||} t| dr| j} n|r|j|jj||ng} x|| D]t} tj | } tj | }t || |f<|j | |d|d|d|}|dk r| j|qqW|stj|||j}xC| D]}|j|qjWqX|j|jj||| dtn||j} | dk rtj | } tj | }t || |f<|j | |d|d|d|}nd}|s6|||jyscs@s!|]}tj|dVqdS(R:N(RR,(R-R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pys ~sN(RPR.R/R-R5R:(R.R/(RRRtsetattrR1R RR,RPRNtto_listt column_sett to_column_setR5R:Rftpersist_selectablettarget(RUtattrt attr_valuetvalR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR#Ms8    4c!C@s td|jjd|jjd|jjd|jjd|jd|jd|jd|jjd |j jd |j d |j d |j d |j d|d|j d|j|_}|j|_|j|_|j|_|j |_ |j|_ |j|_|j|_|j|_|j|_dS(Ntparent_persist_selectabletchild_persist_selectabletparent_local_selectabletchild_local_selectableR.R-R/tparent_equivalentstchild_equivalentstconsider_as_foreign_keysRCR:tself_referentialR]t support_synctcan_be_synced_fn(t JoinConditionRgR2Rft local_tableR.R-R/t_equivalent_columnsRR5RCR:RR3t_columns_are_mappedR(R2tremote_columnst local_columnstsynchronize_pairstforeign_key_columnst_calculated_foreign_keystsecondary_synchronize_pairs(RUtjc((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR$s4                      cC@sl|jjrhtj|jjdtj|j rhtj d|j|jjj |jjj fndS(sOTest that this relationship is legal, warn about inheritance conflicts.RsAttempting 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' N( Rgt non_primaryRR RZRNt has_propertyR[RRRSR(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR"s  cC@s|jS(s\Return the current cascade setting for this :class:`.RelationshipProperty`. (R(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt _get_cascadescC@sPt|}d|jkr+|j|n||_|jrL||j_ndS(NR(R t__dict__R%Rt_dependency_processorRO(RURO((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt _set_cascades    cC@s|jrG|j rG|jtks1|jtkrGtjd|n|jtkrs|jrstj d|n|jdkrd|ksd|krtjd|n|jr|j j j j |j|jjfndS(NsOn %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().slOn %s, 'passive_deletes' is normally configured on one-to-many, one-to-one, many-to-many relationships only.tallR s delete-orphans^On %s, can't set passive_deletes='all' in conjunction with 'delete' or 'delete-orphan' cascade(t delete_orphanR4R2RRRRRSR7RRRtprimary_mappert_delete_orphansRR[RgRZ(RURO((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR%s$      cC@s&|j|jko%|j|j|kS(saReturn True if this property will persist values on behalf of the given mapper. (R[t relationships(RUR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt _persists_forscG@srxk|D]c}|jdk r7|jjj|r7qn|jjjj| r|jjj| rtSqWtS(sReturn True if all columns in the given collection are mapped by the tables referenced by this :class:`.Relationship`. N( R-R1Rtcontains_columnRgR2R3RNR (RUtcolsR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRDs  c C@s)|jjrdS|jdk r |j r t|jtjrQ|ji}}n|j\}}|jj }|j st |j j |j}xI|D]>}|j|r|j rtjd|||fqqWn|jdk r$|jd|jj}|jd|jj}nB|jd|jj}|jdd}|rftjdn|jd|j}|jj } |jd|j|jd|j|jd |j||_t| |j||d|d |j|} |j || n|jr%|j!|jndS( shInterpret 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/sOCan't assign 'secondaryjoin' on a backref against a non-secondary relationship.RVR3R0R9RQ("RgRLRTR1RQR{Rt string_typesRRTtconcreteRLtiterate_to_roottuniontself_and_descendantsRMRRRSR-tpopR(tsecondaryjoin_minus_localtprimaryjoin_minus_localtprimaryjoin_reverse_remoteRR5t setdefaultR3R0R9R$R[t_configure_propertyR( RUt backref_keyRRtchecktmRpRqRVRgR%((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR's^        cC@sI|jdkr$|jtk |_n|jsEtjj||_ndS(N( R+R1R2RR3RtDependencyProcessortfrom_relationshipRP(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR&Ns   cC@s|j}|jS(sPmemoize the 'use_get' attribute of this RelationshipLoader's lazyloader.(Rtuse_get(RUtstrategy((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRVs cC@s|jj|jS(N(RRRg(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR^sc C@s<|dkr0|r0|jjr0|jj}q0nt}|dkr|jj}|ri|jjrit}n|j r|dkr|j }t}qnt}|p|j}|j }|p|dk }|j j ||||\} } } } }|dkr |jj}n|dkr&|jj}n| | ||| | fS(N(R1Rgtwith_polymorphicRiRNRfRhRR RRRR(t join_targetsRB( RURlRkRRRmtaliasedt dest_mapperRR.R/R-Rt((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRnbs6        !  (,RRRtstrategy_wildcard_keyR1RPRtdeprecated_paramsRNR R*R\RRFRRRRRRRRR RRRRfRR*R#R$R"RNRQReROR%RWRDR'R&RRRn(((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR$Zs     4 ^  X 7  7      L c@s1fd|dk r-|}n|S(Nc@s>t|tjr*|jj}n|jd|S(Ntclone(R{Rt ColumnClauseRtcopyt_copy_internals(telem(t annotationsRr(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRrs(R1(telementRw((RwRrsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRs RAc B@seZd&d&d&d&d&d&d&d&ed&edd ZdZdZdZe dZ e dZ e j dZdZe j d Ze j d Zd Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$e%j&Z'dZ(e j dZ)e j d Z*e j d!Z+d"Z,d#Z-d&d$Z.ed%Z/RS('cG@stS(N(R (R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyttcC@s0||_||_||_||_||_| |_||_||_||_| |_ | |_ | |_ ||_ | |_ ||_||_|j|j|j|j|j|j|j|j|jt|jdk r|j|jtn|j|j|jdS(N(R7R9R8R:R;R<R.R/R-R=RWt _remote_sideR]R>R?R@t_determine_joinst_sanitize_joinst _annotate_fkst_annotate_remotet_annotate_localt_annotate_parentmappert _setup_pairst_check_foreign_colsR R1RNt_determine_directiont_check_remote_sidet _log_joins(RUR7R8R9R:R.R-R/R;R<R=RCR:R>R]R?R@((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR*s:                         cC@sP|jdkrdS|jj}|jd|j|j|jd|j|j|jd|jdjd|jD|jd|jdjd|jpgD|jd|jdjd |j D|jd |jdjd |j D|jd |jdjd |j D|jd|j|j dS(Ns%s setup primary join %ss%s setup secondary join %ss%s synchronize pairs [%s]t,cs@s%|]\}}d||fVqdS(s (%s => %s)N((R-tlR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pys ss#%s secondary synchronize pairs [%s]cs@s%|]\}}d||fVqdS(s (%s => %s)N((R-RR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pys ss%s local/remote pairs [%s]cs@s%|]\}}d||fVqdS(s (%s / %s)N((R-RR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pys ss%s remote columns [%s]cs@s|]}d|VqdS(s%sN((R-R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pys ss%s local columns [%s]cs@s|]}d|VqdS(s%sN((R-R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pys ss%s relationship direction %s( R]R1tloggerRJR.R/tjoinRGRJRCRERFR2(RUR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRs< cC@sFt|jdd|_|jdk rBt|jdd|_ndS(sbremove the parententity annotation from our join conditions which can leak in here based on some declarative patterns and maybe others. We'd want to remove "parentmapper" also, but apparently there's an exotic use case in _join_fixture_inh_selfref_w_entity that relies upon it being present, see :ticket:`3364`. tvaluesRXN(RX(RX(RR.R/R1(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR}s cC@s|jdk r7|jdkr7tjd|jny|jpFd}|jdk r|jdkrt|j|jd|j d||_n|j dkrt|j |jd|j d||_ qn9|j dkrt|j |jd|j d||_ nWntj k rd|jdk rKtj d|j|jfqtj d|jn[tjk r|jdk rtjd|j|jfqtjd|jnXdS( sDetermine 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. sMProperty %s specified with secondary join condition but no secondary argumentta_subsetR=s1Could 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.sCould 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.slCould 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/R1R-RRRSR]R=RR8R:R.R7R9tNoForeignKeysErrortAmbiguousForeignKeysError(RUR=((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR| sR      cC@st|jddS(NRtlocalR(RR(RR.(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRai scC@st|jddS(NRRR(RR(RR/(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR`m scC@sU|jr(d}tj|ji|S|jrDt|jddSt|jSdS(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. cS@s|d|jkr<|jj}|d=t|d<|j|Sd|jkrx|jj}|d=t|d<|j|SdS(NRR(t _annotationsRtR t_with_annotations(Rxtv((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytreplace~ s   RRRN(RR(t_has_remote_annotationsRtreplacement_traverseR.t_has_foreign_annotationsR(RUR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRbq s   cC@s8x1tj|iD]}||jkrtSqWtSdS(N(RtiterateRR RN(RURt annotationR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt_has_annotation scC@s|j|jdS(NR"(RR.(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR scC@s|j|jdS(NR(RR.(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR scC@s1|jr dS|jr#|jn |jdS(sAnnotate the primaryjoin and secondaryjoin structures with 'foreign' annotations marking columns considered as foreign. N(RR=t_annotate_from_fk_listt_annotate_present_fks(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR~ s    c@s[fd}tjji|_jdk rWtjji|_ndS(Nc@s'|jkr#|jitd6SdS(NR"(R=RR (R(RU(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytcheck_fk s(RRR.R/R1(RUR((RUsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR s c@s|jdk r'tj|jjn tfdfd}tj|jii|d6|_|j dk rtj|j ii|d6|_ ndS(Nc@st|tjrMt|tjrM|j|r7|S|j|rM|Snr|kro|kro|S|kr|kr|SndS(N(R{RtColumnt references(tatb(t secondarycols(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt is_foreign s$c@st|jtj s,t|jtj r0dSd|jjkrd|jjkr|j|j}|dk r|j|jr|jjit d6|_q|j|jr|jjit d6|_qqndS(NR"( R{tleftRt ColumnElementtrightRR1tcompareRR (tbinaryR(R(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt visit_binary s  R( R-R1RR0RRLRRR.R/(RUR((RRsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR s  c@sU|j|jtgfd}tj|jii|d6dS(svReturn True if the join condition contains column comparisons where both columns are in both tables. c@s|j|j}}t|tjrt|tjrj|jrj|jrj|jrj|jrtd| r>t|_qtjd|jn:|rit|_n(|r{t|_ntjd|jdS(s[Determine if this relationship is one to many, many to one, many to many. RR"sDCan'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.sCan't determine relationship direction for relationship '%s' - foreign key columns are present in neither the parent nor the child's mapped tablesN(R/R1RR2RR0R7RR8t intersectionRHRR.RLRRERFt differenceRRRRRSR]( RUt parentcolst targetcolst onetomany_fkt manytoone_fktonetomany_localRtmanytoone_localt self_equated((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR) sB           cC@s/g|D]$\}}|j|jf^qS(sprovide 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(RUt collectionRR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt_deannotate_pairs} sc@sg}tjgg}fd}xKj|fj|fgD]+\}}|dkrjqLn|||qLWj_j|_j|_dS(Nc@s&fd}t||dS(Nc@sd|jkrCd|jkrCj|rCj||fnCd|jkrd|jkrj|rj||fn|jtjkrj||rd|jkrj||fqd|jkrj||fqndS(NRR"(RR@RtoperatorRteqR(RRR(RtlrpRU(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR s (R(tjoincondRR(RRU(RsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytgo s( Rt OrderedSetR.R/R1RRCRGRJ(RUt sync_pairstsecondary_sync_pairsRRR((RRUsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR s  c @s|js dSxg|jD]\}|f^qg|jD]\}|f^q?D]O\}tjdkrq\n|jkrtji||j6|j s(R?RGRJtlenRVt_track_overlapping_sync_targetstweakreftWeakKeyDictionaryR]titemsRRt_mapper_registryRWRgRMRRRR(RUtfrom_t other_propst prop_to_fromRR((RsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR) s8 %3#   cC@s |jdS(NR(t_gather_join_annotations(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRE scC@s |jdS(NR(R(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRF scC@s |jdS(NR"(R(RU((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRH scC@sWt|j|j|}|jdk rI|j|j|j|nd|DS(NcS@sh|]}|jqS((R(R-R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pys s (RLRR.R/R1tupdate(RURts((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR scG@sGt|}tgtj|iD]}|j|jr"|^q"S(N(RLRRtissubsetR(RURRR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR s  c C@st|itd6}|j|j|j}}}|dk re|dk rX||@}qe||@}n|r}|dk r|jdt}t|}t|d|jj |} |dk rt|j t|d|j }n| j |}n^t|dt dd|j}|dk rP|j t|dt dd|j nd} |j |}| pn|} d| _ nd} |||| |fS(s7Given 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. Rtflatt equivalentst exclude_fnRRN(RR R.R/R-R1RRR<tchainR;Rt_ColInAnnotationsR( RURkRRnRR.R/R-tprimary_aliasizertsecondary_aliasizerRt((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRm sT               c @stjtj}|jdk rztjtx|jD]-\}}|j||f||| s (Rt column_dictR/R1t collectionst defaultdicttlistRCRR.RRRR( RURtequated_columnsRRRt lazywhereR/R((RRRRsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytcreate_lazy_clauseg s4    N(0RRR1RNR R*RR}R|ReRaR`RRRbRRRR~RRRRRRRRRRRRRRRRRRRRRR)RERFRHRRRmR(((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyRAsb (  [#   .       /     B T +  @ QRcB@s eZdZdZdZRS(sKSeralizable equivalent to: lambda c: "name" in c._annotations cC@s ||_dS(N(tname(RUR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR* scC@s|j|jkS(N(RR(RUR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyt__call__ s(RRRR*R(((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pyR s (3Rt __future__RRRRzRRRRtbaseRt interfacesRRRRR RR R R R RRRRRt inspectionRRRRtsql.utilRRRRRRRRR"t class_loggert langhelperstdependency_forR R$RtobjectRAR(((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/relationships.pytsd    B