ÿØÿà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@sdZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd l m Z dd l m Z dd l mZdd l mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlmZddl!m"Z"ddl!mZ#ddl!m$Z$dd l%m&Z&dd!l'm(Z(dd"l)m*Z*d#d$d%gZ+ej,Z-ej.e j/d#e0fd&YZ1d'e*fd(YZ2d)e0fd*YZ3d+e3fd,YZ4ej.d-efd.YZ5d/e3fd0YZ6d1e3fd2YZ7d$e0fd3YZ8d4ej9fd5YZ:d6S(7sThe Query class and support. Defines the :class:`.Query` class, the central construct used by the ORM to construct database queries. The :class:`.Query` class should not be confused with the :class:`.Select` class, which defines database SELECT operations at the SQL (non-ORM) level. ``Query`` differs from ``Select`` in that it returns ORM-mapped objects and interacts with an ORM session, whereas the ``Select`` construct interacts directly with the database to return iterable result sets. i(tchaini(t attributes(texc(t interfaces(tloading(t persistence(t properties(t_entity_descriptor(t _generative(t_is_aliased_class(t_is_mapped_class(t _orm_columns(tInspectionAttr(t PathRegistry(t_entity_corresponds_to(taliased(t AliasedClass(tjoin(t object_mapper(t ORMAdapter(t with_parenti(tinspect(t inspection(tlog(tsql(tutil(t expression(tvisitors(tColumnCollection(t_interpret_as_from(t ForUpdateArgtQueryt QueryContextRcBs+eZdZeZeZeZeZe Z e Z eZ eZ e ZeZe Ze Ze Ze Ze Ze ZeZeZeZeZeZe Ze Ze ZfZfZ e Z!iZ"fZ#e Z$e%j&Z'Z(e%j&Z)e%j&Z*e%j&Z+fZ,fZ-eZ.eZ/eZ0e1Z2eZ3e Z4e dZ5e dZ6dZ7dZ8dZ9dZ:dZ;dZ<e=d Z>e=d Z?d Z@d ZAd ZBdZCeDdZEdZFdZGdZHe dZIdZJdZKdZLeedZMeedZNdZOdZPdZQe e e e e dZRdZSeDdZTe eedZUe ed ZVd!ZWd"ZXeDd#ZYd$ZZe=d%Z[e=d&Z\d'Z]e=d(Z^e=d)Z_eDd*Z`e=d+Zae=eOe e d,Zbe=d-Zcd.Zde eejfe d/Zge d0Zhe=d1Zie=d2Zje=d3Zke=d4Zle e d5Zme=e d6Zne=d7Zod8Zpe=d9Zqe=d:Zrd;ZsesZtd<Zue=d=Zve=d>Zwe%jxd?d@edAZydBZzdCZ{e=dDZ|dEZ}e=dFdGZ~dFdHZdIZe=dJZe=e%jdKdLdMZe=eee eedNZe=dOZe=ePeQdPZdQZe=ePeQdRZe=ePeQdSZe=ePeQdTZdUZdVZdWZdXZdYZdZZd[Zd\Zd]Zd^Ze=ePeQd_Zd`ZdaZdbZdcZddZe=ePdeZe=eOdfZe=eOdgZdhZe=ePdiZe=ePdjZe=ePdkZe=ePdlZe=dmZe=dnZdoZe=eOdpZdqZdrZdsZdtZduZdvZdwZdxZdyZdzZeDd{Ze d|Zed}ZeDd~ZeDdZdZdZddZde dZedZdZdZdZRS(sLORM-level SQL construction object. :class:`.Query` is the source of all SELECT statements generated by the ORM, both those formulated by end-user query operations as well as by high level internal operations such as related collection loading. It features a generative interface whereby successive calls return a new :class:`.Query` object, a copy of the former with additional criteria and options associated with it. :class:`.Query` objects are normally initially generated using the :meth:`~.Session.query` method of :class:`.Session`, and in less common cases by instantiating the :class:`.Query` directly and associating with a :class:`.Session` using the :meth:`.Query.with_session` method. For a full walkthrough of :class:`.Query` usage, see the :ref:`ormtutorial_toplevel`. cCs#||_i|_|j|dS(sConstruct a :class:`.Query` directly. E.g.:: q = Query([User, Address], session=some_session) The above is equivalent to:: q = some_session.query(User, Address) :param entities: a sequence of entities and/or SQL expressions. :param session: a :class:`.Session` with which the :class:`.Query` will be associated. Optional; a :class:`.Query` can be associated with a :class:`.Session` generatively via the :meth:`.Query.with_session` method as well. .. seealso:: :meth:`.Session.query` :meth:`.Query.with_session` N(tsessiont_polymorphic_adapterst _set_entities(tselftentitiesR!((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt__init__s  cCsz|dkrt}ng|_d|_t|_|dk rvx$tj|D]}|||qLW|j|jndS(N(( tNonet _QueryEntityt _entitiest_primary_entitytFalset_has_mapper_entitiesRtto_listt_set_entity_selectables(R$R%tentity_wrappertent((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR#s      cCs|jj|_}x|D]}x|jD]}||krt|}|j r|jjr|jj|jkr|j |jt j |j |jj nd}n|jr|j}nd}||f||         cCsXxQ|jD]F}|jj|dx*|jD]}|jj|jdq0Wq WdS(N(RBR"tpopR'RCRD(R$R4RFRG((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_reset_polymorphic_adapterscCsd|jkrG|jd}|jj|d}|rG|j|Snt|tjrb|}nt|dr}|j }ndS|jj|d}|r|j|SdS(Nt parententityttable( t _annotationsR"tgetR't adapt_clauseRORt FromClauseRHRc(R$telementtsearchRQ((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_adapt_polymorphic_element$s   cCs/g|D]$}|jtj|tt^qS(N(t _adapt_clauseRt_literal_as_label_referencetTrue(R$tcolsto((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_adapt_col_list6scCs ||_dS(N(tlazy_loaded_from(R$tstate((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_set_lazyload_from>scCs t|_dS(N(R+t_orm_only_adapt(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_adapt_all_clausesBscsg|jst}n|rT|jrTx*|jD]}j||jfq1Wn|jrj|jrr|nt|jjfn|jrj||jfns|Sfd}t j |i|S(s\Adapt incoming clauses to transformations which have been applied within this query.csed|jkpd|jk}x@D]8\}}| s>|r%||}|dk r]|Sq%q%WdS(Nt _orm_adaptRb(RdR'(telemt is_orm_adaptt _orm_onlyREte(tadapters(sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytreplacefs   ( RtR+t_filter_aliasesRMR|RWt_orm_only_from_obj_aliasR"RjRtreplacement_traverse(R$tclauset as_filtertorm_onlyRZR|((R{sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRkFs      cCs |jdS(sReturn the first QueryEntity.i(R)(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_query_entity_zerosscCs|jdjS(s8return the Mapper associated with the first QueryEntity.i(R)R4(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt _mapper_zerowscCs#|jdk r|jS|jjS(sReturn the 'entity' (mapper or AliasedClass) associated with the first QueryEntity, or alternatively the 'select from' entity if specified.N(RJR'Rt entity_zero(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt _entity_zero{sccs/x(|jD]}t|tr |Vq q WdS(N(R)ROt _MapperEntity(R$R0((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_mapper_entitiesscCs|jjd|jS(Nt_joinpoint_entity(t _joinpointReR(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_joinpoint_zeroscCs;|j}|dk r7t|}|js7|jSndS(N(RR'Rtis_clause_elementR4(R$tezerotinsp((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt _bind_mappers      cCs5|j|jgkr+tjd|n|jjS(Ns4%s() can only be used against a single mapped class.(R)R*RKtInvalidRequestErrorR(R$tmethname((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_only_full_mapper_zeros  cCs7t|jdkr-tj|p$dn|jS(Nis8This operation requires a Query against a single mapper.(RTR)RKRR(R$t rationale((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_only_entity_zeros  cCs1i}x$|jD]}|j|jjqW|S(N(RtupdateR4R;(R$R^R0((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt __all_equivsscCs|jddtdtS(NRetorder_bytdistinct(t_no_criterion_conditionR+(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_get_conditionscCs|jddtdtdS(NReRR(t_no_criterion_assertionR+(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_get_existing_conditionscCs|js dS|jdk sy|jdk sy|jsy|jdk sy|jdk sy|jsy|rj|jsy|r|j rt j d|ndS(Ns<Query.%s() being called on a Query with existing criterion. ( t_enable_assertionst _criterionR't _statementRSt_limitt_offsett _group_byt _order_byt _distinctRKR(R$tmethRR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs   cCsG|j|||d|_d|_|_t|_|_|_dS(N(( RRSR'RRR+RRR(R$RRR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs cCs=|js dS|jr,tjd|n|j|dS(Ns<Query.%s() being called on a Query with existing criterion. (RRRKRR(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_no_clauseelement_conditions   cCs6|js dS|jdk r2tjd|ndS(Ns[Query.%s() being called on a Query with an existing full statement - can't apply criterion.(RRR'RKR(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_no_statement_conditions  cCsK|js dS|jdk s+|jdk rGtjd||fndS(NsQuery.%s() being called on a Query which already has LIMIT or OFFSET applied. To modify the row-limited results of a Query, call from_self() first. Otherwise, call %s() before limit() or offset() are applied.(RRR'RRKR(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_no_limit_offsets  cCsd|r||_n|r$||_n|r6||_n|rNt||_n|r`||_n|S(N(t_populate_existingt_version_checkt_refresh_statetsett_only_load_propst_refresh_identity_token(R$tpopulate_existingt version_checktonly_load_propst refresh_statetidentity_token((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt _get_optionss    cCs.|j}|j|}|jj|_|S(N(t __class__t__new__t__dict__R2(R$tclstq((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_clones cCs:|jd|jj}|jr6|j|j}n|S(sThe full SELECT statement represented by this Query. The statement by default will not have disambiguating labels applied to the construct unless with_labels(True) is called first. tlabels(t_compile_contextt _with_labelst statementt_paramstparams(R$tstmt((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR s  cCsR|jt}|r$|j}n|j}|rB|j}n|jd|S(sMreturn the full SELECT statement represented by this :class:`.Query`, embedded within an :class:`.Alias`. Eager JOIN generation within the query is disabled. :param name: string name to be assigned as the alias; this is passed through to :meth:`.FromClause.alias`. If ``None``, a name will be deterministically generated at compile time. :param with_labels: if True, :meth:`.with_labels` will be called on the :class:`.Query` first to apply table-qualified labels to all columns. :param reduce_columns: if True, :meth:`.Select.reduce_columns` will be called on the resulting :func:`.select` construct, to remove same-named columns where one also refers to the other via foreign key or WHERE clause equivalence. tname(tenable_eagerloadsR+t with_labelsRtreduce_columnsRQ(R$RRRR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytsubquerys cCs"|jtjjd|d|S(s*Return the full SELECT statement represented by this :class:`.Query` represented as a common table expression (CTE). Parameters and usage are the same as those of the :meth:`.SelectBase.cte` method; see that method for further details. Here is the `PostgreSQL WITH RECURSIVE example `_. Note that, in this example, the ``included_parts`` cte and the ``incl_alias`` alias of it are Core selectables, which means the columns are accessed via the ``.c.`` attribute. The ``parts_alias`` object is an :func:`.orm.aliased` instance of the ``Part`` entity, so column-mapped attributes are available directly:: from sqlalchemy.orm import aliased class Part(Base): __tablename__ = 'part' part = Column(String, primary_key=True) sub_part = Column(String, primary_key=True) quantity = Column(Integer) included_parts = session.query( Part.sub_part, Part.part, Part.quantity).\ filter(Part.part=="our part").\ cte(name="included_parts", recursive=True) incl_alias = aliased(included_parts, name="pr") parts_alias = aliased(Part, name="p") included_parts = included_parts.union_all( session.query( parts_alias.sub_part, parts_alias.part, parts_alias.quantity).\ filter(parts_alias.part==incl_alias.c.sub_part) ) q = session.query( included_parts.c.sub_part, func.sum(included_parts.c.quantity). label('total_quantity') ).\ group_by(included_parts.c.sub_part) .. seealso:: :meth:`.HasCTE.cte` Rt recursive(RR+Rtcte(R$RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR:s7cCs|jtjj|S(sReturn the full SELECT statement represented by this :class:`.Query`, converted to a scalar subquery with a label of the given name. Analogous to :meth:`sqlalchemy.sql.expression.SelectBase.label`. (RR+Rtlabel(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRus cCs|jtjjS(sReturn the full SELECT statement represented by this :class:`.Query`, converted to a scalar subquery. Analogous to :meth:`sqlalchemy.sql.expression.SelectBase.as_scalar`. (RR+Rt as_scalar(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRscCs |jS(sReturn the :class:`.Select` object emitted by this :class:`.Query`. Used for :func:`.inspect` compatibility, this is equivalent to:: query.enable_eagerloads(False).with_labels().statement (t__clause_element__(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR:s cCs|jtjjS(N(RR+RR(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRscCs ||_dS(sWhen set to True, the query results will always be a tuple, specifically for single element queries. The default is False. . .. versionadded:: 1.2.5 N(t_only_return_tuples(R$tvalue((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytonly_return_tuplesscCs ||_dS(sControl whether or not eager joins and subqueries are rendered. When set to False, the returned Query will not render eager joins regardless of :func:`~sqlalchemy.orm.joinedload`, :func:`~sqlalchemy.orm.subqueryload` options or mapper-level ``lazy='joined'``/``lazy='subquery'`` configurations. This is used primarily when nesting the Query's statement into a subquery or other selectable, or when using :meth:`.Query.yield_per`. N(t_enable_eagerloads(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRscCstjd|dS(NsThe yield_per Query option is currently not compatible with %s eager loading. Please specify lazyload('*') or query.enable_eagerloads(False) in order to proceed with query.yield_per().(RKR(R$tmessage((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt _no_yield_perscCs t|_dS(sApply column labels to the return value of Query.statement. Indicates that this Query's `statement` accessor should return a SELECT statement that applies labels to all columns in the form _; this is commonly used to disambiguate columns from multiple tables which have the same name. When the `Query` actually issues SQL to load rows, it always uses column labeling. .. note:: The :meth:`.Query.with_labels` method *only* applies the output of :attr:`.Query.statement`, and *not* to any of the result-row invoking systems of :class:`.Query` itself, e.g. :meth:`.Query.first`, :meth:`.Query.all`, etc. To execute a query using :meth:`.Query.with_labels`, invoke the :attr:`.Query.statement` using :meth:`.Session.execute`:: result = session.execute(query.with_labels().statement) N(RmR(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRscCs ||_dS(sControl whether assertions are generated. When set to False, the returned Query will not assert its state before certain operations, including that LIMIT/OFFSET has not been applied when filter() is called, no criterion exists when get() is called, and no "from_statement()" exists when filter()/order_by()/group_by() etc. is called. This more permissive mode is used by custom Query subclasses to specify criterion or other modifiers outside of the usual usage patterns. Care should be taken to ensure that the usage pattern is even possible. A statement applied by from_statement() will override any criterion set by filter() or order_by(), for example. N(R(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytenable_assertionsscCs|jS(sA readonly attribute which returns the current WHERE criterion for this Query. This returned value is a SQL expression construct, or ``None`` if no criterion has been established. (R(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt whereclauses cCs ||_dS(sindicate that this query applies to objects loaded within a certain path. Used by deferred loaders (see strategies.py) which transfer query options from an originating query to a newly generated query intended for the deferred load. N(t _current_path(R$tpath((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_with_current_paths cCse|jstjdn|jdj}|g|jd|_|j||d|d|dS(sLoad columns for inheriting classes. :meth:`.Query.with_polymorphic` applies transformations to the "main" mapped class represented by this :class:`.Query`. The "main" mapped class here means the :class:`.Query` object's first argument is a full class, i.e. ``session.query(SomeClass)``. These transformations allow additional tables to be present in the FROM clause so that columns for a joined-inheritance subclass are available in the query, both for the purposes of load-time efficiency as well as the ability to use these columns at query time. See the documentation section :ref:`with_polymorphic` for details on how this method is used. s(No primary mapper set up for this Query.iiR:tpolymorphic_onN(R*RKRR)Rtset_with_polymorphic(R$tcls_or_mappersR:RR?((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR5s  cCs0||_|jjitd6|d6|_dS(s Yield only ``count`` rows at a time. The purpose of this method is when fetching very large result sets (> 10K rows), to batch results in sub-collections and yield them out partially, so that the Python interpreter doesn't need to declare very large areas of memory which is both time consuming and leads to excessive memory use. The performance from fetching hundreds of thousands of rows can often double when a suitable yield-per setting (e.g. approximately 1000) is used, even with DBAPIs that buffer rows (which are most). The :meth:`.Query.yield_per` method **is not compatible subqueryload eager loading or joinedload eager loading when using collections**. It is potentially compatible with "select in" eager loading, **provided the database driver supports multiple, independent cursors** (pysqlite and psycopg2 are known to work, MySQL and SQL Server ODBC drivers do not). Therefore in some cases, it may be helpful to disable eager loads, either unconditionally with :meth:`.Query.enable_eagerloads`:: q = sess.query(Object).yield_per(100).enable_eagerloads(False) Or more selectively using :func:`.lazyload`; such as with an asterisk to specify the default loader scheme:: q = sess.query(Object).yield_per(100).\ options(lazyload('*'), joinedload(Object.some_related)) .. warning:: Use this method with caution; if the same instance is present in more than one batch of rows, end-user changes to attributes will be overwritten. In particular, it's usually impossible to use this setting with eagerly loaded collections (i.e. any lazy='joined' or 'subquery') since those collections will be cleared for a new load when encountered in a subsequent result batch. In the case of 'subquery' loading, the full result for all rows is fetched which generally defeats the purpose of :meth:`~sqlalchemy.orm.query.Query.yield_per`. Also note that while :meth:`~sqlalchemy.orm.query.Query.yield_per` will set the ``stream_results`` execution option to True, currently this is only understood by :mod:`~sqlalchemy.dialects.postgresql.psycopg2`, :mod:`~sqlalchemy.dialects.mysql.mysqldb` and :mod:`~sqlalchemy.dialects.mysql.pymysql` dialects which will stream results using server side cursors instead of pre-buffer all rows for this query. Other DBAPIs **pre-buffer all rows** before making them available. The memory use of raw database rows is much less than that of an ORM-mapped object, but should still be taken into consideration when benchmarking. .. seealso:: :meth:`.Query.enable_eagerloads` tstream_resultstmax_row_bufferN(t _yield_pert_execution_optionstunionRm(R$tcount((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt yield_per&sA  cCs|j|tjS(sReturn an instance based on the given primary key identifier, or ``None`` if not found. E.g.:: my_user = session.query(User).get(5) some_object = session.query(VersionedFoo).get((5, 10)) some_object = session.query(VersionedFoo).get( {"id": 5, "version_id": 10}) :meth:`~.Query.get` is special in that it provides direct access to the identity map of the owning :class:`.Session`. If the given primary key identifier is present in the local identity map, the object is returned directly from this collection and no SQL is emitted, unless the object has been marked fully expired. If not present, a SELECT is performed in order to locate the object. :meth:`~.Query.get` also will perform a check if the object is present in the identity map and marked as expired - a SELECT is emitted to refresh the object as well as to ensure that the row is still present. If not, :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised. :meth:`~.Query.get` is only used to return a single mapped instance, not multiple instances or individual column constructs, and strictly on a single primary key value. The originating :class:`.Query` must be constructed in this way, i.e. against a single mapped entity, with no additional filtering criterion. Loading options via :meth:`~.Query.options` may be applied however, and will be used if the object is not yet locally present. A lazy-loading, many-to-one attribute configured by :func:`.relationship`, using a simple foreign-key-to-primary-key criterion, will also use an operation equivalent to :meth:`~.Query.get` in order to retrieve the target value from the local identity map before querying the database. See :doc:`/orm/loading_relationships` for further details on relationship loading. :param ident: A scalar, tuple, or dictionary representing the primary key. For a composite (e.g. multiple column) primary key, a tuple or dictionary should be passed. For a single-column primary key, the scalar calling form is typically the most expedient. If the primary key of a row is the value "5", the call looks like:: my_object = query.get(5) The tuple form contains primary key values typically in the order in which they correspond to the mapped :class:`.Table` object's primary key columns, or if the :paramref:`.Mapper.primary_key` configuration parameter were used, in the order used for that parameter. For example, if the primary key of a row is represented by the integer digits "5, 10" the call would look like:: my_object = query.get((5, 10)) The dictionary form should include as keys the mapped attribute names corresponding to each element of the primary key. If the mapped class has the attributes ``id``, ``version_id`` as the attributes which store the object's primary key value, the call would look like:: my_object = query.get({"id": 5, "version_id": 10}) .. versionadded:: 1.3 the :meth:`.Query.get` method now optionally accepts a dictionary of attribute names to values in order to indicate a primary key identifier. :return: The object instance, or ``None``. (t _get_implRtload_on_pk_identity(R$tident((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRelsScCs+|j|d|}tj|j||S(skLocate an object in the identity map. Given a primary key identity, constructs an identity key and then looks in the session's identity map. If present, the object may be run through unexpiration rules (e.g. load unloaded attributes, check if was deleted). For performance reasons, while the :class:`.Query` must be instantiated, it may be instantiated with no entities, and the mapper is passed:: obj = session.query()._identity_lookup(inspect(SomeClass), (1, )) :param mapper: mapper in use :param primary_key_identity: the primary key we are searching for, as a tuple. :param identity_token: identity token that should be used to create the identity key. Used as is, however overriding subclasses can repurpose this in order to interpret the value in a special way, such as if None then look among multiple target tokens. :param passive: passive load flag passed to :func:`.loading.get_from_identity`, which impacts the behavior if the object is found; the object may be validated and/or unexpired if the flag allows for SQL to be emitted. :param lazy_loaded_from: an :class:`.InstanceState` that is specifically asking for this identity as a related identity. Used for sharding schemes where there is a correspondence between an object and a related object being lazy-loaded (or otherwise relationship-loaded). .. versionadded:: 1.2.9 :return: None if the object is not found in the identity map, *or* if the object was unexpired and found to have been deleted. if passive flags disallow SQL and the object is expired, returns PASSIVE_NO_RESULT. In all other cases the instance is returned. .. versionadded:: 1.2.7 R(tidentity_key_from_primary_keyRtget_from_identityR!(R$R4tprimary_key_identityRtpassiveRqtkey((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_identity_lookups1cstdrjn|jd}tt}|sTtjntt|jkrt j ddj d|jDn|ry#t fd|j DWqtk rt j ddj d|j DqXn|j ru|j ru|jdkru|j|d |}|dk ru|jt|j|jsndS|Sn||S( Nt__composite_values__ResmIncorrect number of values in identifier to formulate primary key for query.get(); primary key columns are %st,css|]}d|VqdS(s'%s'N((t.0tc((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pys sc3s|]}|jVqdS(N(R(Rtprop(R(sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pys sstIncorrect names of values in identifier to formulate primary key for query.get(); primary key attribute names are %scss|]}d|jVqdS(s'%s'N(R(RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pys sR(RHRRROtdictRR-RTt primary_keyRKRRtlistt_identity_key_propstKeyErrorRtalways_refresht_for_update_argR'RRt issubclassRtclass_(R$Rt db_load_fnRR4tis_dicttinstance((RsG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs@#      cGs`xY|D]Q}|dkr4|jjdg|_q|jjtjt||_qWdS(s"Return a :class:`.Query` construct which will correlate the given FROM clauses to that of an enclosing :class:`.Query` or :func:`~.expression.select`. The method here accepts mapped classes, :func:`.aliased` constructs, and :func:`.mapper` constructs as arguments, which are resolved into expression constructs, in addition to appropriate expression constructs. The correlation arguments are ultimately passed to :meth:`.Select.correlate` after coercion to expression constructs. The correlation arguments take effect in such cases as when :meth:`.Query.from_self` is used, or when a subquery as returned by :meth:`.Query.subquery` is embedded in another :func:`~.expression.select` construct. N(R't _correlateRR8tsurface_selectablesR(R$targsts((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt correlate/s    cCs ||_dS(s%Return a Query with a specific 'autoflush' setting. Note that a Session with autoflush=False will not autoflush, even if this flag is set to True at the Query level. Therefore this flag is usually used only to disable autoflush for a specific Query. N(t _autoflush(R$tsetting((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt autoflushLs cCs t|_dS(sReturn a :class:`.Query` that will expire and refresh all instances as they are loaded, or reused from the current :class:`.Session`. :meth:`.populate_existing` does not improve behavior when the ORM is used normally - the :class:`.Session` object's usual behavior of maintaining a transaction and expiring all attributes after rollback or commit handles object state automatically. This method is not intended for general use. N(RmR(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRXs cCs ||_dS(sSet the 'invoke all eagers' flag which causes joined- and subquery loaders to traverse into already-loaded related objects and collections. Default is that of :attr:`.Query._invoke_all_eagers`. N(t_invoke_all_eagers(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_with_invoke_all_eagersfs cCs|rt|}n |j}|dkrt|}xj|jD]4}t|tjrC|j|jkrC|}PqCqCWt j d|jj j |j j fn|jt|||jS(sAdd filtering criterion that relates the given instance to a child object or collection, using its attribute state as well as an established :func:`.relationship()` configuration. The method uses the :func:`.with_parent` function to generate the clause, the result of which is passed to :meth:`.Query.filter`. Parameters are the same as :func:`.with_parent`, with the exception that the given property can be None, in which case a search is performed against this :class:`.Query` object's target mapper. :param instance: An instance which has some :func:`.relationship`. :param property: String property name, or class-bound attribute, which indicates what relationship from the instance should be used to reconcile the parent/child relationship. :param from_entity: Entity in which to consider as the left side. This defaults to the "zero" entity of the :class:`.Query` itself. s\Could not locate a property which relates instances of class '%s' to instances of class '%s'N(RRR'Rtiterate_propertiesRORtRelationshipPropertyR4RKRRt__name__RtfilterRR?(R$Rtpropertyt from_entityRR4R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRqs    cCsS|dk rt||}nt|j|_t||}|j|gdS(sIadd a mapped entity to the list of result columns to be returned.N(R'RRR)RR.(R$R?RQRG((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt add_entitys  cCs ||_dS(sReturn a :class:`.Query` that will use the given :class:`.Session`. While the :class:`.Query` object is normally instantiated using the :meth:`.Session.query` method, it is legal to build the :class:`.Query` directly without necessarily using a :class:`.Session`. Such a :class:`.Query` object, or any :class:`.Query` already associated with a different :class:`.Session`, can produce a new :class:`.Query` object associated with a target session using this method:: from sqlalchemy.orm import Query query = Query([MyClass]).filter(MyClass.id == 5) result = query.with_session(my_session).one() N(R!(R$R!((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt with_sessionscGsb|jjtjjd}|j|}t|_|j|_ |r^|j |n|S(sreturn a Query that selects from this Query's SELECT statement. :meth:`.Query.from_self` essentially turns the SELECT statement into a SELECT of itself. Given a query such as:: q = session.query(User).filter(User.name.like('e%')) Given the :meth:`.Query.from_self` version:: q = session.query(User).filter(User.name.like('e%')).from_self() This query renders as: .. sourcecode:: sql SELECT anon_1.user_id AS anon_1_user_id, anon_1.user_name AS anon_1_user_name FROM (SELECT "user".id AS user_id, "user".name AS user_name FROM "user" WHERE "user".name LIKE :name_1) AS anon_1 There are lots of cases where :meth:`.Query.from_self` may be useful. A simple one is where above, we may want to apply a row LIMIT to the set of user objects we query against, and then apply additional joins against that row-limited set:: q = session.query(User).filter(User.name.like('e%')).\ limit(5).from_self().\ join(User.addresses).filter(Address.email.like('q%')) The above query joins to the ``Address`` entity but only against the first five results of the ``User`` query: .. sourcecode:: sql SELECT anon_1.user_id AS anon_1_user_id, anon_1.user_name AS anon_1_user_name FROM (SELECT "user".id AS user_id, "user".name AS user_name FROM "user" WHERE "user".name LIKE :name_1 LIMIT :param_1) AS anon_1 JOIN address ON anon_1.user_id = address.user_id WHERE address.email LIKE :email_1 **Automatic Aliasing** Another key behavior of :meth:`.Query.from_self` is that it applies **automatic aliasing** to the entities inside the subquery, when they are referenced on the outside. Above, if we continue to refer to the ``User`` entity without any additional aliasing applied to it, those references wil be in terms of the subquery:: q = session.query(User).filter(User.name.like('e%')).\ limit(5).from_self().\ join(User.addresses).filter(Address.email.like('q%')).\ order_by(User.name) The ORDER BY against ``User.name`` is aliased to be in terms of the inner subquery: .. sourcecode:: sql SELECT anon_1.user_id AS anon_1_user_id, anon_1.user_name AS anon_1_user_name FROM (SELECT "user".id AS user_id, "user".name AS user_name FROM "user" WHERE "user".name LIKE :name_1 LIMIT :param_1) AS anon_1 JOIN address ON anon_1.user_id = address.user_id WHERE address.email LIKE :email_1 ORDER BY anon_1.user_name The automatic aliasing feature only works in a **limited** way, for simple filters and orderings. More ambitious constructions such as referring to the entity in joins should prefer to use explicit subquery objects, typically making use of the :meth:`.Query.subquery` method to produce an explicit subquery object. Always test the structure of queries by viewing the SQL to ensure a particular structure does what's expected! **Changing the Entities** :meth:`.Query.from_self` also includes the ability to modify what columns are being queried. In our example, we want ``User.id`` to be queried by the inner query, so that we can join to the ``Address`` entity on the outside, but we only wanted the outer query to return the ``Address.email`` column:: q = session.query(User).filter(User.name.like('e%')).\ limit(5).from_self(Address.email).\ join(User.addresses).filter(Address.email.like('q%')) yielding: .. sourcecode:: sql SELECT address.email AS address_email FROM (SELECT "user".id AS user_id, "user".name AS user_name FROM "user" WHERE "user".name LIKE :name_1 LIMIT :param_1) AS anon_1 JOIN address ON anon_1.user_id = address.user_id WHERE address.email LIKE :email_1 **Looking out for Inner / Outer Columns** Keep in mind that when referring to columns that originate from inside the subquery, we need to ensure they are present in the columns clause of the subquery itself; this is an ordinary aspect of SQL. For example, if we wanted to load from a joined entity inside the subquery using :func:`.contains_eager`, we need to add those columns. Below illustrates a join of ``Address`` to ``User``, then a subquery, and then we'd like :func:`.contains_eager` to access the ``User`` columns:: q = session.query(Address).join(Address.user).\ filter(User.name.like('e%')) q = q.add_entity(User).from_self().\ options(contains_eager(Address.user)) We use :meth:`.Query.add_entity` above **before** we call :meth:`.Query.from_self` so that the ``User`` columns are present in the inner subquery, so that they are available to the :func:`.contains_eager` modifier we are using on the outside, producing: .. sourcecode:: sql SELECT anon_1.address_id AS anon_1_address_id, anon_1.address_email AS anon_1_address_email, anon_1.address_user_id AS anon_1_address_user_id, anon_1.user_id AS anon_1_user_id, anon_1.user_name AS anon_1_user_name FROM ( SELECT address.id AS address_id, address.email AS address_email, address.user_id AS address_user_id, "user".id AS user_id, "user".name AS user_name FROM address JOIN "user" ON "user".id = address.user_id WHERE "user".name LIKE :name_1) AS anon_1 If we didn't call ``add_entity(User)``, but still asked :func:`.contains_eager` to load the ``User`` entity, it would be forced to add the table on the outside without the correct join criteria - note the ``anon1, "user"`` phrase at the end: .. sourcecode:: sql -- incorrect query SELECT anon_1.address_id AS anon_1_address_id, anon_1.address_email AS anon_1_address_email, anon_1.address_user_id AS anon_1_address_user_id, "user".id AS user_id, "user".name AS user_name FROM ( SELECT address.id AS address_id, address.email AS address_email, address.user_id AS address_user_id FROM address JOIN "user" ON "user".id = address.user_id WHERE "user".name LIKE :name_1) AS anon_1, "user" :param \*entities: optional list of entities which will replace those being selected. N( RRR+RRR't_from_selectablet_enable_single_critRRJR#(R$R%t fromclauseR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt from_selfs    cCs ||_dS(N(R(R$tval((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_set_enable_single_crit}sc Cs~x!dD]}|jj|dqW|j|gtt|_|j}g|_x%|D]}|j||j d qYWdS(NRRRRRRt _joinpathRRt_havingt _prefixest _suffixesi( RRRRRRRRRRRR( RR`R'R_RmR+R~R)tadapt_to_selectableRS(R$Rtattrt old_entitiesRz((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR s(     cGsN|stdS|j}|j|dt|jsDd|_nt|S(s\Return an iterator yielding result tuples corresponding to the given list of columnsR/i ((titerRR#t _ColumnEntityR(R$tcolumnsR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytvaluess    cCs4yt|j|dSWntk r/dSXdS(sLReturn a scalar result corresponding to the given column expression.iN(tnextRt StopIterationR'(R$tcolumn((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs cGs|j|dS(s)Return a new :class:`.Query` replacing the SELECT list with the given entities. e.g.:: # Users, filtered on some arbitrary criterion # and then ordered by related email address q = session.query(User).\ join(User.address).\ filter(User.name.like('%ed%')).\ order_by(Address.email) # given *only* User.id==5, Address.email, and 'q', what # would the *next* User in the result be ? subq = q.with_entities(Address.email).\ order_by(None).\ filter(User.id==5).\ subquery() q = q.join((subq, subq.c.email < Address.email)).\ limit(1) N(R#(R$R%((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt with_entitiesscGsWt|j|_t|j}x|D]}t||q(W|j|j|dS(sXAdd one or more column expressions to the list of result columns to be returned.N(RR)RTRR.(R$R tlR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt add_columnss  s0.7s9:meth:`.add_column` is superseded by :meth:`.add_columns`cCs |j|S(sAdd a column expression to the list of result columns to be returned. Pending deprecation: :meth:`.add_column` will be superseded by :meth:`.add_columns`. (R#(R$R ((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt add_columns cGs|jt|S(s>Return a new :class:`.Query` object, applying the given list of mapper options. Most supplied options regard changing how column- and relationship-mapped attributes are loaded. .. seealso:: :ref:`deferred_options` :ref:`relationship_loader_options` (t_optionsR+(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytoptionsscGs|jt|S(N(R%Rm(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_conditional_optionsscGs|jj|_d|jkr4t|jd 5) The criterion is any SQL expression object applicable to the WHERE clause of a select. String expressions are coerced into SQL expression constructs via the :func:`.text` construct. .. seealso:: :meth:`.Query.filter_by` - filter on keyword expressions. N(RRt_expression_literal_as_textRkRmRR'(R$t criterion((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs cKsGg|jD]'\}}t|j||k^q }|j|S(sapply the given filtering criterion to a copy of this :class:`.Query`, using keyword expressions. e.g.:: session.query(MyClass).filter_by(name = 'some name') Multiple criteria may be specified as comma separated; the effect is that they will be joined together using the :func:`.and_` function:: session.query(MyClass).\ filter_by(name = 'some name', id = 5) The keyword expressions are extracted from the primary entity of the query, or the last entity that was the target of a call to :meth:`.Query.join`. .. seealso:: :meth:`.Query.filter` - filter on SQL expressions. (titemsRRR(R$R:RRtclauses((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt filter_bys7cGst|dkra|dtkrAd|jkr=t|_ndS|ddkrad|_dSn|j|}|jtks|jdkr||_n|j||_dS(sZapply one or more ORDER BY criterion to the query and return the newly resulting ``Query`` All existing ORDER BY settings can be suppressed by passing ``None`` - this will suppress any ordering configured on the :func:`.mapper` object using the deprecated :paramref:`.mapper.order_by` parameter. iiRN(RTR+RRR'Rp(R$RG((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR s    cGst|dkr2|ddkr2t|_dSnttg|D]}t|^q?}|j|}|jtkr||_n|j||_dS(sapply one or more GROUP BY criterion to the query and return the newly resulting :class:`.Query` All existing GROUP BY settings can be suppressed by passing ``None`` - this will suppress any GROUP BY configured on mappers as well. .. versionadded:: 1.1 GROUP BY can be cancelled by passing None, in the same way as ORDER BY. iiN(RTR'R+RRRR Rp(R$RGR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytgroup_by(s + cCstj|}|dk r@t|tj r@tjdn|j|t t }|j dk rw|j |@|_ n ||_ dS(s apply a HAVING criterion to the query and return the newly resulting :class:`.Query`. :meth:`~.Query.having` is used in conjunction with :meth:`~.Query.group_by`. HAVING criterion makes it possible to use filters on aggregate functions like COUNT, SUM, AVG, MAX, and MIN, eg.:: q = session.query(User.id).\ join(User.addresses).\ group_by(User.id).\ having(func.count(Address.id) > 2) sHhaving() argument must be of type sqlalchemy.sql.ClauseElement or stringN( RRFR'RORt ClauseElementRKRLRkRmR(R$RG((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pythavingCs cGs)|j||gt|jtS(N(R RRR+(R$texpr_fnR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_set_opfscGs|jtj|S(sProduce a UNION of this Query against one or more queries. e.g.:: q1 = sess.query(SomeClass).filter(SomeClass.foo=='bar') q2 = sess.query(SomeClass).filter(SomeClass.bar=='foo') q3 = q1.union(q2) The method accepts multiple Query objects so as to control the level of nesting. A series of ``union()`` calls such as:: x.union(y).union(z).all() will nest on each ``union()``, and produces:: SELECT * FROM (SELECT * FROM (SELECT * FROM X UNION SELECT * FROM y) UNION SELECT * FROM Z) Whereas:: x.union(y, z).all() produces:: SELECT * FROM (SELECT * FROM X UNION SELECT * FROM y UNION SELECT * FROM Z) Note that many database backends do not allow ORDER BY to be rendered on a query called within UNION, EXCEPT, etc. To disable all ORDER BY clauses including those configured on mappers, issue ``query.order_by(None)`` - the resulting :class:`.Query` object will not render ORDER BY within its SELECT statement. (RORR(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRks%cGs|jtj|S(sProduce a UNION ALL of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RORt union_all(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRPscGs|jtj|S(sProduce an INTERSECT of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RORt intersect(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRQscGs|jtj|S(sProduce an INTERSECT ALL of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RORt intersect_all(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRRscGs|jtj|S(sProduce an EXCEPT of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RORtexcept_(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRSscGs|jtj|S(sProduce an EXCEPT ALL of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RORt except_all(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRTsc Os|jdt|jdt|jdt|jdtf\}}}}|rvtddjt|n|j|d|d|d|d|S( s*Create a SQL JOIN against this :class:`.Query` object's criterion and apply generatively, returning the newly resulting :class:`.Query`. **Simple Relationship Joins** Consider a mapping between two classes ``User`` and ``Address``, with a relationship ``User.addresses`` representing a collection of ``Address`` objects associated with each ``User``. The most common usage of :meth:`~.Query.join` is to create a JOIN along this relationship, using the ``User.addresses`` attribute as an indicator for how this should occur:: q = session.query(User).join(User.addresses) Where above, the call to :meth:`~.Query.join` along ``User.addresses`` will result in SQL equivalent to:: SELECT user.* FROM user JOIN address ON user.id = address.user_id In the above example we refer to ``User.addresses`` as passed to :meth:`~.Query.join` as the *on clause*, that is, it indicates how the "ON" portion of the JOIN should be constructed. For a single-entity query such as the one above (i.e. we start by selecting only from ``User`` and nothing else), the relationship can also be specified by its string name:: q = session.query(User).join("addresses") :meth:`~.Query.join` can also accommodate multiple "on clause" arguments to produce a chain of joins, such as below where a join across four related entities is constructed:: q = session.query(User).join("orders", "items", "keywords") The above would be shorthand for three separate calls to :meth:`~.Query.join`, each using an explicit attribute to indicate the source entity:: q = session.query(User).\ join(User.orders).\ join(Order.items).\ join(Item.keywords) **Joins to a Target Entity or Selectable** A second form of :meth:`~.Query.join` allows any mapped entity or core selectable construct as a target. In this usage, :meth:`~.Query.join` will attempt to create a JOIN along the natural foreign key relationship between two entities:: q = session.query(User).join(Address) The above calling form of :meth:`~.Query.join` will raise an error if either there are no foreign keys between the two entities, or if there are multiple foreign key linkages between them. In the above calling form, :meth:`~.Query.join` is called upon to create the "on clause" automatically for us. The target can be any mapped entity or selectable, such as a :class:`.Table`:: q = session.query(User).join(addresses_table) **Joins to a Target with an ON Clause** The third calling form allows both the target entity as well as the ON clause to be passed explicitly. Suppose for example we wanted to join to ``Address`` twice, using an alias the second time. We use :func:`~sqlalchemy.orm.aliased` to create a distinct alias of ``Address``, and join to it using the ``target, onclause`` form, so that the alias can be specified explicitly as the target along with the relationship to instruct how the ON clause should proceed:: a_alias = aliased(Address) q = session.query(User).\ join(User.addresses).\ join(a_alias, User.addresses).\ filter(Address.email_address=='ed@foo.com').\ filter(a_alias.email_address=='ed@bar.com') Where above, the generated SQL would be similar to:: SELECT user.* FROM user JOIN address ON user.id = address.user_id JOIN address AS address_1 ON user.id=address_1.user_id WHERE address.email_address = :email_address_1 AND address_1.email_address = :email_address_2 The two-argument calling form of :meth:`~.Query.join` also allows us to construct arbitrary joins with SQL-oriented "on clause" expressions, not relying upon configured relationships at all. Any SQL expression can be passed as the ON clause when using the two-argument form, which should refer to the target entity in some way as well as an applicable source entity:: q = session.query(User).join(Address, User.id==Address.user_id) **Advanced Join Targeting and Adaption** There is a lot of flexibility in what the "target" can be when using :meth:`~.Query.join`. As noted previously, it also accepts :class:`.Table` constructs and other selectables such as :func:`.alias` and :func:`.select` constructs, with either the one or two-argument forms:: addresses_q = select([Address.user_id]).\ where(Address.email_address.endswith("@bar.com")).\ alias() q = session.query(User).\ join(addresses_q, addresses_q.c.user_id==User.id) :meth:`~.Query.join` also features the ability to *adapt* a :meth:`~sqlalchemy.orm.relationship` -driven ON clause to the target selectable. Below we construct a JOIN from ``User`` to a subquery against ``Address``, allowing the relationship denoted by ``User.addresses`` to *adapt* itself to the altered target:: address_subq = session.query(Address).\ filter(Address.email_address == 'ed@foo.com').\ subquery() q = session.query(User).join(address_subq, User.addresses) Producing SQL similar to:: SELECT user.* FROM user JOIN ( SELECT address.id AS id, address.user_id AS user_id, address.email_address AS email_address FROM address WHERE address.email_address = :email_address_1 ) AS anon_1 ON user.id = anon_1.user_id The above form allows one to fall back onto an explicit ON clause at any time:: q = session.query(User).\ join(address_subq, User.id==address_subq.c.user_id) **Controlling what to Join From** While :meth:`~.Query.join` exclusively deals with the "right" side of the JOIN, we can also control the "left" side, in those cases where it's needed, using :meth:`~.Query.select_from`. Below we construct a query against ``Address`` but can still make usage of ``User.addresses`` as our ON clause by instructing the :class:`.Query` to select first from the ``User`` entity:: q = session.query(Address).select_from(User).\ join(User.addresses).\ filter(User.name == 'ed') Which will produce SQL similar to:: SELECT address.* FROM user JOIN address ON user.id=address.user_id WHERE user.name = :name_1 **Constructing Aliases Anonymously** :meth:`~.Query.join` can construct anonymous aliases using the ``aliased=True`` flag. This feature is useful when a query is being joined algorithmically, such as when querying self-referentially to an arbitrary depth:: q = session.query(Node).\ join("children", "children", aliased=True) When ``aliased=True`` is used, the actual "alias" construct is not explicitly available. To work with it, methods such as :meth:`.Query.filter` will adapt the incoming entity to the last join point:: q = session.query(Node).\ join("children", "children", aliased=True).\ filter(Node.name == 'grandchild 1') When using automatic aliasing, the ``from_joinpoint=True`` argument can allow a multi-node join to be broken into multiple calls to :meth:`~.Query.join`, so that each path along the way can be further filtered:: q = session.query(Node).\ join("children", aliased=True).\ filter(Node.name='child 1').\ join("children", aliased=True, from_joinpoint=True).\ filter(Node.name == 'grandchild 1') The filtering aliases above can then be reset back to the original ``Node`` entity using :meth:`~.Query.reset_joinpoint`:: q = session.query(Node).\ join("children", "children", aliased=True).\ filter(Node.name == 'grandchild 1').\ reset_joinpoint().\ filter(Node.name == 'parent 1) For an example of ``aliased=True``, see the distribution example :ref:`examples_xmlpersistence` which illustrates an XPath-like query system using algorithmic joins. :param \*props: A collection of one or more join conditions, each consisting of a relationship-bound attribute or string relationship name representing an "on clause", or a single target entity, or a tuple in the form of ``(target, onclause)``. A special two-argument calling form of the form ``target, onclause`` is also accepted. :param aliased=False: If True, indicate that the JOIN target should be anonymously aliased. Subsequent calls to :meth:`~.Query.filter` and similar will adapt the incoming criterion to the target alias, until :meth:`~.Query.reset_joinpoint` is called. :param isouter=False: If True, the join used will be a left outer join, just as if the :meth:`.Query.outerjoin` method were called. This flag is here to maintain consistency with the same flag as accepted by :meth:`.FromClause.join` and other Core constructs. .. versionadded:: 1.0.0 :param full=False: render FULL OUTER JOIN; implies ``isouter``. .. versionadded:: 1.1 :param from_joinpoint=False: When using ``aliased=True``, a setting of True here will cause the join to be from the most recent joined target, rather than starting back from the original FROM clauses of the query. .. seealso:: :ref:`ormtutorial_joins` in the ORM tutorial. :ref:`inheritance_toplevel` for details on how :meth:`~.Query.join` is used for inheritance relationships. :func:`.orm.join` - a standalone ORM-level join function, used internally by :meth:`.Query.join`, which in previous SQLAlchemy versions was the primary ORM-level joining interface. Rtfrom_joinpointtisoutertfullsunknown arguments: %ss, t outerjointcreate_aliases(R`R+t TypeErrorRtsortedt_join(R$tpropsR:RRURVRW((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs!c Os|jdt|jdt|jdt}}}|r`tddjt|n|j|dtd|d|d|S(sCreate a left outer join against this ``Query`` object's criterion and apply generatively, returning the newly resulting ``Query``. Usage is the same as the ``join()`` method. RRURWsunknown arguments: %ss, RXRY(R`R+RZRR[R\Rm(R$R]R:RRURW((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRXscCse||_xLd|krW|d\}}|j}|||<||f|d<|}q W||_dS(Ntprev(RR2R(R$tjptfR^((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_update_joinpoints    c Csu|s|jnt|dkrrt|dtjttfrrt|dttjt j frr|f}nt j |}xt |D]\}}t|tr|\}} nd } t|t j t jfr| |} } n || } } | d kr=t| } | j r=t| d r=tjdq=nt| t j rdt| dd } nd } t| t jrt|j| } nc|rt| t j r|j}t|}t|dd | jkrt|| j} qnt| t j rD| d kr3| r$| } q3| jj} n| j}|jj|d }t|tr|j j!|r|j"}t|| j} n| j}t| t#j$s|} n|sN|| |jf}||j%krA|j%|j&}||j%f|d<|j'||t|dkrt j(d|qqqAqNn d }}|j)|| | ||||qWd S( sconsumes arguments from join() or outerjoin(), places them into a consistent format with which to form the actual JOIN constructs. iiiR4s9Expected mapped entity or selectable/table as join targett_of_typeR^s:Pathed join target %s has already been joined to; skippingN(*t_reset_joinpointRTRORRgttypeRtstrRLRtPropComparatorRR-t enumerateRRR't string_typesRRNRHRKRLtgetattrRRt _parententityRR R?R"ReRR4tisat aliased_classRtQueryableAttributeRR2Ratwarnt_join_left_to_right(R$tkeysRXRWRYRUtkeylisttidxtarg1targ2trighttonclausetr_infotof_typetjp0R]tleftRQRtedgeR_((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR\sz           !       c Csy|jj|_|dkrQ|dks0t|j|||\}}} n'|dk sct|j|\}} ||kr| rtjd||fn|j|||||\} }}|dk r%|j |} |j | t | ||d|d|f|j |d|_ nP| dk rD|j | j } n|} |j t | ||d|d|f|_ dS(sgiven raw "left", "right", "onclause" parameters consumed from a particular key within _join(), add a real ORMJoin object to our _from_obj list (or augment an existing one) s>Can't construct a join from %s to %s, they are the same entityRVRWiN( R"R2R'tAssertionErrort"_join_determine_implicit_left_sidet_join_place_explicit_left_sideRKRt _join_check_and_adapt_right_sideRStorm_joinR)R:( R$RzRuRvRRYRXRWtreplace_from_obj_indextuse_entity_indexRwt left_clause((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRoy s*  !  A cCst|}d}}|jrtj|j|j|}t|dkrf|d}|j|}qt|dkrtjdqtjd|fnC|j ri}xt |j D]}\} } | j } | dkrqnt| } | |krqnt | t r,| | f|| j|dk r>|jp$d||_|||_nU|dkrb|dk rb||_n1|dk r|dkr|jpd||_n|jdkrd|_ndS(sComputes the "slice" of the :class:`.Query` represented by the given indices and returns the resulting :class:`.Query`. The start and stop indices behave like the argument to Python's built-in :func:`range` function. This method provides an alternative to using ``LIMIT``/``OFFSET`` to get a slice of the query. For example, :: session.query(User).order_by(User.id).slice(1, 3) renders as .. sourcecode:: sql SELECT users.id AS users_id, users.name AS users_name FROM users ORDER BY users.id LIMIT ? OFFSET ? (2, 1) .. seealso:: :meth:`.Query.limit` :meth:`.Query.offset` iN(R'RR(R$RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR s cCs ||_dS(sZApply a ``LIMIT`` to the query and return the newly resulting ``Query``. N(R(R$tlimit((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR scCs ||_dS(s\Apply an ``OFFSET`` to the query and return the newly resulting ``Query``. N(R(R$toffset((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR scGsR|st|_n<|j|}t|jtrE|j|7_n ||_dS(s{Apply a ``DISTINCT`` to the query and return the newly resulting ``Query``. .. note:: The :meth:`.distinct` call includes logic that will automatically add columns from the ORDER BY of the query to the columns clause of the SELECT statement, to satisfy the common need of the database backend that ORDER BY columns be part of the SELECT list when DISTINCT is used. These columns *are not* added to the list of columns actually fetched by the :class:`.Query`, however, so would not affect results. The columns are passed through when using the :attr:`.Query.statement` accessor, however. :param \*expr: optional column expressions. When present, the PostgreSQL dialect will render a ``DISTINCT ON ()`` construct. N(RmRRpROR(R$texpr((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR s  cGs(|jr|j|7_n ||_dS(sApply the prefixes to the query and return the newly resulting ``Query``. :param \*prefixes: optional prefixes, typically strings, not using any commas. In particular is useful for MySQL keywords and optimizer hints: e.g.:: query = sess.query(User.name).\ prefix_with('HIGH_PRIORITY').\ prefix_with('SQL_SMALL_RESULT', 'ALL').\ prefix_with('/*+ BKA(user) */') Would render:: SELECT HIGH_PRIORITY SQL_SMALL_RESULT ALL /*+ BKA(user) */ users.name AS users_name FROM users .. seealso:: :meth:`.HasPrefixes.prefix_with` N(R(R$tprefixes((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt prefix_with+ s cGs(|jr|j|7_n ||_dS(sGApply the suffix to the query and return the newly resulting ``Query``. :param \*suffixes: optional suffixes, typically strings, not using any commas. .. versionadded:: 1.0.0 .. seealso:: :meth:`.Query.prefix_with` :meth:`.HasSuffixes.suffix_with` N(R(R$tsuffixes((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt suffix_withJ s cCs t|S(sReturn the results represented by this ``Query`` as a list. This results in an execution of the underlying query. (R(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytall` scCsItj|}t|tjtjfs<tjdn||_dS(s%Execute the given SELECT statement and return results. This method bypasses all internal statement compilation, and the statement is executed without modification. The statement is typically either a :func:`~.expression.text` or :func:`~.expression.select` construct, and should return the set of columns appropriate to the entity class represented by this :class:`.Query`. .. seealso:: :ref:`orm_tutorial_literal_sql` - usage examples in the ORM tutorial sBfrom_statement accepts text(), select(), and union() objects only.N(RRFROt TextClauseRPRKRLR(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytfrom_statementh s  cCsZ|jdk r%t|dd!}nt|dd!}t|dkrR|dSdSdS(sReturn the first result of this ``Query`` or None if the result doesn't contain any row. first() applies a limit of one within the generated SQL, so that only one primary entity row is generated on the server side (note this may consist of multiple result rows if join-loaded collections are present). Calling :meth:`.Query.first` results in an execution of the underlying query. .. seealso:: :meth:`.Query.one` :meth:`.Query.one_or_none` iiN(RR'RRT(R$tret((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytfirst s cCsOt|}t|}|dkr,|dS|dkr<dStjddS(sxReturn at most one result or raise an exception. Returns ``None`` if the query selects no rows. Raises ``sqlalchemy.orm.exc.MultipleResultsFound`` if multiple object identities are returned, or if multiple rows are returned for a query that returns only scalar values as opposed to full identity-mapped entities. Calling :meth:`.Query.one_or_none` results in an execution of the underlying query. .. versionadded:: 1.0.9 Added :meth:`.Query.one_or_none` .. seealso:: :meth:`.Query.first` :meth:`.Query.one` iis*Multiple rows were found for one_or_none()N(RRTR'torm_exctMultipleResultsFound(R$RR"((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt one_or_none s    cCs\y|j}Wn#tjk r5tjdn#X|dkrTtjdn|SdS(s6Return exactly one result or raise an exception. Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects no rows. Raises ``sqlalchemy.orm.exc.MultipleResultsFound`` if multiple object identities are returned, or if multiple rows are returned for a query that returns only scalar values as opposed to full identity-mapped entities. Calling :meth:`.one` results in an execution of the underlying query. .. seealso:: :meth:`.Query.first` :meth:`.Query.one_or_none` s"Multiple rows were found for one()sNo row was found for one()N(RRRR't NoResultFound(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytone s  cCsGy+|j}t|ts"|S|dSWntjk rBdSXdS(s4Return the first element of the first result or None if no rows present. If multiple rows are returned, raises MultipleResultsFound. >>> session.query(Item).scalar() >>> session.query(Item.id).scalar() 1 >>> session.query(Item.id).filter(Item.id < 0).scalar() None >>> session.query(Item.id, Item.name).scalar() 1 >>> session.query(func.count(Parent.id)).scalar() 20 This results in an execution of the underlying query. iN(RRORRRRR'(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytscalar s  cCsH|j}t|j_|jr;|j r;|jjn|j|S(N(RRmRt use_labelsRRR!t_execute_and_instances(R$tcontext((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt__iter__ s   cCsj|j}y+|jr0|j||jjnd}Wntjk rSd}nXt|jj |S(N( RR!t_get_bind_argstget_bindR'RKtUnboundExecutionErrorReRtcompile(R$Rtbind((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt__str__ s !  cKs4|jj|}|jr0|j|j}n|S(N(R!t connectionRR;(R$tkwtconn((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_connection_from_session s cCsI|j||jdt}|j|j|j}tj|j||S(Ntclose_with_result( RRRmtexecuteRRRt instancestquery(R$t querycontextRtresult((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR scCs1|jd|d|dt}|j||jS(NR4RR(RRmRR(R$RR4R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt _execute_crud s cKs|d|jd|j|S(NR4R(RR(R$RR1R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR% scCsgg|jD]0}||jdk r4t|jndf^q D]u\}}i|jd6|jd6t|dtd6|jd6|jdk r|j rt|ddndd6^qAS(sReturn metadata about the columns which would be returned by this :class:`.Query`. Format is a list of dictionaries:: user_alias = aliased(User, name='user2') q = sess.query(User, User.id, user_alias) # this expression: q.column_descriptions # would return: [ { 'name':'User', 'type':User, 'aliased':False, 'expr':User, 'entity': User }, { 'name':'id', 'type':Integer(), 'aliased':False, 'expr':User.id, 'entity': User }, { 'name':'user2', 'type':User, 'aliased':True, 'expr':user_alias, 'entity': user_alias } ] RRdR3RRR?N( R)RR'Rt _label_nameRdRiR+RR(R$t_entR0tinsp_ent((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytcolumn_descriptions* s) cCs4|}|dkr!t|}ntj|||S(sGiven a ResultProxy cursor as returned by connection.execute(), return an ORM result as an iterator. e.g.:: result = engine.execute("select * from users") for u in session.query(User).instances(result): print u N(R'R RR(R$tcursort_Query__contextR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRj s  cCstj|||S(s?Merge a result into this :class:`.Query` object's Session. Given an iterator returned by a :class:`.Query` of the same structure as this one, return an identical iterator of results, with all mapped instances merged into the session using :meth:`.Session.merge`. This is an optimized method which will merge all mapped instances, preserving the structure of the result rows and unmapped columns with less method overhead than that of calling :meth:`.Session.merge` explicitly for each value. The structure of the results is determined based on the column list of this :class:`.Query` - if these do not correspond, unchecked errors will occur. The 'load' argument is the same as that of :meth:`.Session.merge`. For an example of how :meth:`~.Query.merge_result` is used, see the source code for the example :ref:`examples_caching`, where :meth:`~.Query.merge_result` is used to efficiently restore state from a cache back into a target :class:`.Session`. (Rt merge_result(R$titeratortload((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRz scCsPi|jd6|jd6|jd6|jd6|jd6|jpAdd6|jd6S(NRRRRRRKRM(RRRRRRR'R(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt _select_args s     cCsC|j}|jddk pB|jddk pB|jdtS(NRRR(RReR'R+(R$R:((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_should_nest_selectable s cCs4tj|jtjdjjjdgS(sA convenience method that turns a query into an EXISTS subquery of the form EXISTS (SELECT 1 FROM ... WHERE ...). e.g.:: q = session.query(User).filter(User.name == 'fred') session.query(q.exists()) Producing SQL similar to:: SELECT EXISTS ( SELECT 1 FROM users WHERE users.name = :name_1 ) AS anon_1 The EXISTS construct is usually used in the WHERE clause:: session.query(User.id).filter(q.exists()).scalar() Note that some databases such as SQL Server don't allow an EXISTS expression to be present in the columns clause of a SELECT. To select a simple boolean value based on the exists as a WHERE, use :func:`.literal`:: from sqlalchemy import literal session.query(literal(True)).filter(q.exists()).scalar() t1i(RtexistsRR+R#RRtwith_only_columns(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR s#cCs.tjjtjd}|j|jS(sReturn a count of rows this Query would return. This generates the SQL for this Query as follows:: SELECT count(1) AS count_1 FROM ( SELECT ) AS anon_1 For fine grained control over specific columns to count, to skip the usage of a subquery or otherwise control of the FROM clause, or to use other aggregate functions, use :attr:`~sqlalchemy.sql.expression.func` expressions in conjunction with :meth:`~.Session.query`, i.e.:: from sqlalchemy import func # count User records, without # using a subquery. session.query(func.count(User.id)) # return count of user "id" grouped # by "name" session.query(func.count(User.id)).\ group_by(User.name) from sqlalchemy import distinct # count distinct "name" values session.query(func.count(distinct(User.name))) R3(RtfuncRtliteral_columnRR(R$tcol((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR s"tevaluatecCs&tjj||}|j|jS(sOPerform a bulk delete query. Deletes rows matched by this query from the database. E.g.:: sess.query(User).filter(User.age == 25).\ delete(synchronize_session=False) sess.query(User).filter(User.age == 25).\ delete(synchronize_session='evaluate') .. warning:: The :meth:`.Query.delete` method is a "bulk" operation, which bypasses ORM unit-of-work automation in favor of greater performance. **Please read all caveats and warnings below.** :param synchronize_session: chooses the strategy for the removal of matched objects from the session. Valid values are: ``False`` - don't synchronize the session. This option is the most efficient and is reliable once the session is expired, which typically occurs after a commit(), or explicitly using expire_all(). Before the expiration, objects may still remain in the session which were in fact deleted which can lead to confusing results if they are accessed via get() or already loaded collections. ``'fetch'`` - performs a select query before the delete to find objects that are matched by the delete query and need to be removed from the session. Matched objects are removed from the session. ``'evaluate'`` - Evaluate the query's criteria in Python straight on the objects in the session. If evaluation of the criteria isn't implemented, an error is raised. The expression evaluator currently doesn't account for differing string collations between the database and Python. :return: the count of rows matched as returned by the database's "row count" feature. .. warning:: **Additional Caveats for bulk query deletes** * This method does **not work for joined inheritance mappings**, since the **multiple table deletes are not supported by SQL** as well as that the **join condition of an inheritance mapper is not automatically rendered**. Care must be taken in any multiple-table delete to first accommodate via some other means how the related table will be deleted, as well as to explicitly include the joining condition between those tables, even in mappings where this is normally automatic. E.g. if a class ``Engineer`` subclasses ``Employee``, a DELETE against the ``Employee`` table would look like:: session.query(Engineer).\ filter(Engineer.id == Employee.id).\ filter(Employee.name == 'dilbert').\ delete() However the above SQL will not delete from the Engineer table, unless an ON DELETE CASCADE rule is established in the database to handle it. Short story, **do not use this method for joined inheritance mappings unless you have taken the additional steps to make this feasible**. * The polymorphic identity WHERE criteria is **not** included for single- or joined- table updates - this must be added **manually** even for single table inheritance. * The method does **not** offer in-Python cascading of relationships - it is assumed that ON DELETE CASCADE/SET NULL/etc. is configured for any foreign key references which require it, otherwise the database may emit an integrity violation if foreign key references are being enforced. After the DELETE, dependent objects in the :class:`.Session` which were impacted by an ON DELETE may not contain the current state, or may have been deleted. This issue is resolved once the :class:`.Session` is expired, which normally occurs upon :meth:`.Session.commit` or can be forced by using :meth:`.Session.expire_all`. Accessing an expired object whose row has been deleted will invoke a SELECT to locate the row; when the row is not found, an :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised. * The ``'fetch'`` strategy results in an additional SELECT statement emitted and will significantly reduce performance. * The ``'evaluate'`` strategy performs a scan of all matching objects within the :class:`.Session`; if the contents of the :class:`.Session` are expired, such as via a proceeding :meth:`.Session.commit` call, **this will result in SELECT queries emitted for every matching object**. * The :meth:`.MapperEvents.before_delete` and :meth:`.MapperEvents.after_delete` events **are not invoked** from this method. Instead, the :meth:`.SessionEvents.after_bulk_delete` method is provided to act upon a mass DELETE of entity rows. .. seealso:: :meth:`.Query.update` :ref:`inserts_and_updates` - Core SQL tutorial (Rt BulkDeletetfactorytexec_trowcount(R$tsynchronize_sessiont delete_op((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytdelete sw cCs8|p i}tjj||||}|j|jS(suPerform a bulk update query. Updates rows matched by this query in the database. E.g.:: sess.query(User).filter(User.age == 25).\ update({User.age: User.age - 10}, synchronize_session=False) sess.query(User).filter(User.age == 25).\ update({"age": User.age - 10}, synchronize_session='evaluate') .. warning:: The :meth:`.Query.update` method is a "bulk" operation, which bypasses ORM unit-of-work automation in favor of greater performance. **Please read all caveats and warnings below.** :param values: a dictionary with attributes names, or alternatively mapped attributes or SQL expressions, as keys, and literal values or sql expressions as values. If :ref:`parameter-ordered mode ` is desired, the values can be passed as a list of 2-tuples; this requires that the :paramref:`~sqlalchemy.sql.expression.update.preserve_parameter_order` flag is passed to the :paramref:`.Query.update.update_args` dictionary as well. .. versionchanged:: 1.0.0 - string names in the values dictionary are now resolved against the mapped entity; previously, these strings were passed as literal column names with no mapper-level translation. :param synchronize_session: chooses the strategy to update the attributes on objects in the session. Valid values are: ``False`` - don't synchronize the session. This option is the most efficient and is reliable once the session is expired, which typically occurs after a commit(), or explicitly using expire_all(). Before the expiration, updated objects may still remain in the session with stale values on their attributes, which can lead to confusing results. ``'fetch'`` - performs a select query before the update to find objects that are matched by the update query. The updated attributes are expired on matched objects. ``'evaluate'`` - Evaluate the Query's criteria in Python straight on the objects in the session. If evaluation of the criteria isn't implemented, an exception is raised. The expression evaluator currently doesn't account for differing string collations between the database and Python. :param update_args: Optional dictionary, if present will be passed to the underlying :func:`.update` construct as the ``**kw`` for the object. May be used to pass dialect-specific arguments such as ``mysql_limit``, as well as other special arguments such as :paramref:`~sqlalchemy.sql.expression.update.preserve_parameter_order`. .. versionadded:: 1.0.0 :return: the count of rows matched as returned by the database's "row count" feature. .. warning:: **Additional Caveats for bulk query updates** * The method does **not** offer in-Python cascading of relationships - it is assumed that ON UPDATE CASCADE is configured for any foreign key references which require it, otherwise the database may emit an integrity violation if foreign key references are being enforced. After the UPDATE, dependent objects in the :class:`.Session` which were impacted by an ON UPDATE CASCADE may not contain the current state; this issue is resolved once the :class:`.Session` is expired, which normally occurs upon :meth:`.Session.commit` or can be forced by using :meth:`.Session.expire_all`. * The ``'fetch'`` strategy results in an additional SELECT statement emitted and will significantly reduce performance. * The ``'evaluate'`` strategy performs a scan of all matching objects within the :class:`.Session`; if the contents of the :class:`.Session` are expired, such as via a proceeding :meth:`.Session.commit` call, **this will result in SELECT queries emitted for every matching object**. * The method supports multiple table updates, as detailed in :ref:`multi_table_updates`, and this behavior does extend to support updates of joined-inheritance and other multiple table mappings. However, the **join condition of an inheritance mapper is not automatically rendered**. Care must be taken in any multiple-table update to explicitly include the joining condition between those tables, even in mappings where this is normally automatic. E.g. if a class ``Engineer`` subclasses ``Employee``, an UPDATE of the ``Engineer`` local table using criteria against the ``Employee`` local table might look like:: session.query(Engineer).\ filter(Engineer.id == Employee.id).\ filter(Employee.name == 'dilbert').\ update({"engineer_type": "programmer"}) * The polymorphic identity WHERE criteria is **not** included for single- or joined- table updates - this must be added **manually**, even for single table inheritance. * The :meth:`.MapperEvents.before_update` and :meth:`.MapperEvents.after_update` events **are not invoked from this method**. Instead, the :meth:`.SessionEvents.after_bulk_update` method is provided to act upon a mass UPDATE of entity rows. .. seealso:: :meth:`.Query.delete` :ref:`inserts_and_updates` - Core SQL tutorial (Rt BulkUpdateRRR(R$RRt update_argst update_op((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRss   cCsu|jjrGx8|jjD]'}||}|dk r|}qqWnt|}|jdk rf|S||_|j|_x!|jD]}|j||qWx)|j D]}|d}||dqW|j rt |j |_ n|j r|j|n|js8|jr&tjdq8tjdn|jr_|jr_|j||_n|j||_|S(NiisyNo column-based properties specified for refresh operation. Use session.expire() to reload collections and related items.s4Query contains no columns with which to SELECT from.(tdispatchtbefore_compileR'R RRRR)t setup_contexttcreate_eager_joinst from_clauseRtfromsRt_adjust_for_single_inheritancetprimary_columnsRRKRtmulti_row_eager_loadersRt_compound_eager_statementt_simple_statement(R$RR1t new_queryRR?trectstrategy((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs:             c Cs|jr$tj|j|j}nd|_g}tj|j||jd|jd|j d|j|j }|j |_ x |j D]}|j |}qW|jr|j|j}n|j}|j}tj|||_tj|g|jd|j }|j dk r<|j jdkr<|j |_ n|}x/|jjD]}tj|||j}qRW|j||jr|j|jj|jn|j|j|S(NR\RR(RR8t expand_column_list_from_order_byRR'RtselectRRRRRR4R7RRRQRVR9REtsecondary_columnsRBt eager_joinsRt splice_joinststop_ont append_fromtappend_order_bytcopy_and_processteager_order_by( R$Rtorder_by_col_exprtinnerthintR^RRt eager_join((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR.sF             c Cs|jsd|_n|jtkrQ|jrQ|jtj|j|j7_n|jt|j j 7_t j |j|j |jd|jd|jd|j|j}|j|_x |jD]}|j|}qW|jr|j|j}n|jr|j|jn|S(NR\RR(RR'RRmRR8RRRRRRRRRRRRRR4R7RRRR(R$RRR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRws,          cCst|jj}|jrx|j|jkrxt|j}|jrT|j}nd}|j|j|fg}nx|D]\}}||j krqn|j j }|dk r|r|j |}n|j |tt}tjtjj|j||_qqWdS(smApply single-table-inheritance filtering. For all distinct single-table-inheritance mappers represented in the columns clause of this query, as well as the "select from entity", add criterion to the WHERE clause of the given QueryContext such that only the appropriate subtypes are selected from the total results. N(RR1RRJRR3R<R'RRR4t_single_table_criterionttraverseRkR+Rtand_tTrue_t_ifnoneR(R$RRiRRER@t single_crit((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs$      (Rt __module__t__doc__R+RRmRRRR'RRRRRRRRRRRRt frozensetRRRRRRRRRSRRJR1R}RWRt immutabledictRRRRR)R+R4RRtR~t_path_registryRR,RqR&R#R.R7R_RaRjRpRRsRuRkRRRR RRRRRRVRRRRRRRRRRRRRRR:RRRRRRRRR5RReRt PASSIVE_OFFRRRRRRRR R RRR Rt_valuesRR!R#tpending_deprecationR$R&R'R%R2R7R8R9R;t deprecatedR?RERRRJRRKRMRORRPRQRRRSRTRRXRaR\RoR}R~RRcRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR@s        /    -           ;       F Y 0 8  6          %# #  '    M ` B  0h *    #       @    * % { 4 I R<cBseZedZRS(cCs|dtfkrdS|dkr1t}t}nG|dkrJt}}n.|dkret}t}ntjd|td|d|S(NR@Rt update_nowaits"Unknown with_lockmode argument: %rRA(R'R+RmRKRLR<(R$R>R@RA((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR=s       (RRt classmethodR=(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR<sR(cBs eZdZdZdZRS(s:represent an entity column returned within a Query result.cOsl|tkr_|d}t|tj r>t|r>t}q_t|trVt}q_t}nt j |S(Ni( R(RORRhR RtBundlet _BundleEntityRtobjectR(RRR:R?((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs      cCs+|jj|j}|jj|_|S(N(RRRR2(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs(RRRRR(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR(s RcBseZdZdZeZeZdZdZe dZ e dZ dZ dZ dZd Zd Zd ZRS( s mapper/class/AliasedClass entitycCsG|js||_n|jj|t|_|g|_||_dS(N(R*R)RMRmR,R%R(R$RR?((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR&s     cCs|j|_||_|j|_|j|_|j|_|j|_||_|jri|jj |_ n|jj j |_ |jj |_dS(N(R4RAR:R3twith_polymorphic_mapperst_with_polymorphicRt_polymorphic_discriminatorRRRRRRR(R$R@RA((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR=s        cCs|jrtdn|dkr8|j|jdS|jj||\}}||_||_||_|j |jt j ||jj dS(sReceive an update from a call to query.with_polymorphic(). Note the newer style of using a free standing with_polymporphic() construct doesn't make use of this method. s6Can't use with_polymorphic() against an Aliased objectN( R3tNotImplementedErrorR'RaR4t_with_polymorphic_argsRRR:R7R8R9R;(R$RRR:RtmappersR\((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs       cCs |jjS(N(R4R(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRd#scCs|jS(N(R(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR'scCst|j|S(N(RR(R$R?((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR+scCs|jj|dS(N(R)RM(R$Rtsel((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR.scCsyd}|js6|jr?|jj|jd}q?n |j}|rl|jrc|j|j}qu|}n |j}|S(N(R'R3R"ReR4RARWtwrap(R$RRRER((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt_get_entity_clauses1s      c Cs|j||}|jr6|r6|j|j}n|sH|j}n| ry|jjrytj|j|jj}n|j |kr|j }|j }n d}}t j|j|||j|d|d|d|j}||jfS(NRRtpolymorphic_discriminator(R%RER$R4t_requires_row_aliasingR8R9R:R;R*RRR'Rt_instance_processorRRR(R$RRRRERRt _instance((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyt row_processorEs,     c Cs|j||}|j|jf7_|jtkr{|jjr{|jj|_|r{|jtj|j|_q{nt j ||j||j ||j d|j d|jd|jdS(NR5RR&(R%RR:RR+R4t adapt_listRR-Rt_setup_entity_queryRRRRR(R$RRRE((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRhs"   cCs t|jS(N(ReR4(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs(RRRR&Rmtsupports_single_entitytuse_id_for_hashR=RR RdRRRR%R*RR(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs       # RcBsneZdZeZeZeZeZdZdZ dZ dZ dZ edZdZdZRS(s>A grouping of SQL expressions that are returned by a :class:`.Query` under one namespace. The :class:`.Bundle` essentially allows nesting of the tuple-based results returned by a column-oriented :class:`.Query` object. It also is extensible via simple subclassing, where the primary capability to override is that of how the set of expressions should be returned, allowing post-processing as well as custom return types, without involving ORM identity-mapped classes. .. versionadded:: 0.9.0 .. seealso:: :ref:`bundles` cOsb||_|_||_t|_|_|jjd|D|jd|j|_dS(sQConstruct a new :class:`.Bundle`. e.g.:: bn = Bundle("mybundle", MyClass.x, MyClass.y) for row in session.query(bn).filter( bn.c.x == 5).filter(bn.c.y == 4): print(row.mybundle.x, row.mybundle.y) :param name: name of the bundle. :param \*exprs: columns or SQL expressions comprising the bundle. :param single_entity=False: if True, rows for this :class:`.Bundle` can be returned as a "single entity" outside of any enclosing tuple in the same manner as a mapped entity. css*|] }t|d|j|fVqdS(RN(Rit_label(RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pys st single_entityN( RR/texprsRRRRR`R0(R$RR1R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR&s   cCs,|jj|j}|jj|j|S(N(RRRR(R$tcloned((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRscCstjdt|jS(Ntgroup(Rt ClauseListR+R1(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRscCs |jjS(N(RRI(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRIscCs|j}||_|S(s<Provide a copy of this :class:`.Bundle` passing a new label.(RR(R$RR2((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs  cs(tjd|fd}|S(sProduce the "row processing" function for this :class:`.Bundle`. May be overridden by subclasses. .. seealso:: :ref:`bundles` - includes an example of subclassing. Rcs#gD]}||^q S(N((trowtproc(t keyed_tupletprocs(sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR6s(Rtlightweight_named_tuple(R$RR8RR6((R7R8sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pytcreate_row_processors N(RRRR+R0RRIR3R&R'RRRRR RIRR:(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs    RcBseZeZedZedZedZedZ dZ edZ dZ dZ dZd ZRS( cCs|jj|||_|_t||_|j|_g|_|rx@|jD]2}t|t ryt ||qTt ||qTWn|jj |_ dS(N(R)RMtbundleRRdRRR1RORRRR0R-(R$RR;tsetup_entitiesR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR&s  cCs$|j}|dk r|jSdSdS(N(RR'R4(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR4s  cCs.g}x!|jD]}|j|jqW|S(N(R)textendR%(R$R%R0((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR%scCs5x.|jD]}|j}|dk r |Sq WdSdS(N(R)RR'(R$R0R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR"s   cCstS(N(R+(R$R?((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR+scCs5x.|jD]}|j}|dk r |Sq WdSdS(N(R)RR'(R$R0R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR0s   cCs@t||jdt}x!|jD]}|j||q"WdS(NR<(RR;R+R)R(R$RR#RR0((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR9scCs(x!|jD]}|j||q WdS(N(R)R=(R$R@RAR0((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR=BscCs(x!|jD]}|j||q WdS(N(R)R(R$RRR0((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRFscCs\tg|jD]}|j|||^q \}}|jj|||}||jfS(N(tzipR)R*R;R:R(R$RRRR0R8RR6((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR*Js 1(RRR+R.RmR&R R4R%RRRRR=RR*(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs    RcBseeZdZd dZeZedZdZ dZ dZ dZ dZ dZRS( sColumn/expression based entity.c Cs||_||_t}t}t|tjr`tj|}|j |_ t}t}d}nt|t j tjfrt|dd}|dk rt}n|j|_ |j}t}t|trt||dSnt|tjs[t|drBx;|jD])}||kr$Pnt||d|qWdSntjd|fn$|st|dd|_ t}n|j|_}|j |_|j rt|dt r|j|j }n|j j!|||_"t#|_$t#|j%|_&} |s`||_'|r9|g|_(|j)|_)ng|_(d|_)t#|j(|_*n gt+j,|dtD]} d| j-krv| ^qv} tj.g| D]"} d| j-kr| j-d^q|_(t#g| D]4} d| j-kr| j/| j%r| j-d^q|_*|j(rG|j(d |_'|j'j)|_)n9|jdk rn|j|_'d|_)nd|_'d|_)dS( NRjt_select_iterablet namespaces<SQL expression, column, or mapped entity expected - got '%r'Rt is_literaltinclude_scalar_selectsRbi(0RR@RmR+RORRhRRRRR'RRmRRfRiRt_query_clause_elementRRt ColumnElementRHR?RRKRRdthashableR.R/RR)RMR RRt _from_objectst actual_fromsRR%R4t_from_entitiesR8tsurface_column_elementsRdt unique_listt intersection( R$RR R@tsearch_entitiest check_columnt_entityRttype_RGRwt all_elements((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR&Zs                   ( +    cCs8|jdk r|jS|jr0t|jdSdSdS(Ni(RR'RGR(R$((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs  cCsCt||j|j}|j|_|j|_|j|_dS(N(Rtcorresponding_columnR RRR%(R$RR#R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs  cCsPd|jkr|j|_n|jj|jjrL|jj|jndS(NR:(RR:RGRKRFRtadd(R$R@RA((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR=scCsP|jdkrtSt|r,||jkSt|j oK|j|jSdS(N(RR'R+R R(R$R?((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRs   cCsd|f|jkr+|jd|f}n|j|jtt}|jr[|j}n|jrw|jj|}n|j |}||j fS(Nt fetch_column( RRkR R+RmRdt _deannotateRERt_getterR(R$RRRR tgetter((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR*s  cCso|j|jtt}|jr0|j}n|jt|j7_|jj |||j d|fRs((-RR'RORRPt_textualRt apply_labelsRRSRRRRRR+RRERRWRR!RRRRRRXRRRRRRRRRRR+RYR)R2RRR(R$R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR&0s@                      (RRERRWRR!RRRXRRRRRRRRYRRRRRRRRZR[R\R(RRt __slots__R&(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR s:t AliasOptioncBseZdZdZRS(cCs ||_dS(s!Return a :class:`.MapperOption` that will indicate to the :class:`.Query` that the main table has been aliased. This is a seldom-used option to suit the very rare case that :func:`.contains_eager` is being used in conjunction with a user-defined SELECT statement that aliases the parent table. E.g.:: # define an aliased UNION called 'ulist' ulist = users.select(users.c.user_id==7).\ union(users.select(users.c.user_id>7)).\ alias('ulist') # add on an eager load of "addresses" statement = ulist.outerjoin(addresses).\ select().apply_labels() # create query, indicating "ulist" will be an # alias for the main table, "addresses" # property should be eager loaded query = session.query(User).options( contains_alias(ulist), contains_eager(User.addresses)) # then get results via the statement results = query.from_statement(statement).all() :param alias: is the string name of an alias, or a :class:`~.sql.expression.Alias` object representing the alias. N(RQ(R$RQ((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR&\s!cCsRt|jtjr3|jjj|j}n |j}tj||_dS(N( RORQRRhRR6R8R9RW(R$RRQ((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyR-s (RRR&R-(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyRa[s #N(;Rt itertoolsRtRRRRRRRtbaseRRR R R R t path_registryR RRRRRRRRRRKRRRRRR8Rtsql.baseRtsql.expressionRtsql.selectableRt__all__trootRt_self_inspectst class_loggerRRR<R(RRRRR t MapperOptionRa(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/query.pyts|   xWK