iddZddlmZddlmZddlmZddlmZddlm Z ddlm Z ddl m Z dd l m Z dd l mZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZGddee ZGddeZGdde Z!e!d@dZ"e"j#dZ"e!dZ$e$j#d Z$e!d@d!Z%e%j#d"Z%e%j&d#Z'e!d$Z(e(j#d%Z(e(j&d&Z)e!d'Z*e*j#d(Z*e*j&d)Z+e!d*Z,e,j#d+Z,e,j&d,Z-e!d-Z.e.j#d.Z.e!d/Z/e/j#d0Z/e!dAd2Z0e0j#d3Z0e!d4Z1e1j#d5Z1e!d6Z2e2j#d7Z2e!d8Z3e3j#d9Z3e!d:Z4e4j#d;Z4e!d<Z5e5j#d=Z5e!d>Z6e6j#d?Z6dS)Bz )util)QueryableAttribute)_class_to_mapper)_is_aliased_class)_is_mapped_class)InspectionAttr) MapperOption)MapperProperty)PropComparator)_DEFAULT_TOKEN)_WILDCARD_TOKEN) PathRegistry) TokenRegistry)_orm_full_deannotate)excinspect) expression) _generative) Generativec$eZdZdZdZedZdZfdZdZ dZ dZ dZ dZ dZd Zd Z dd Zd ZdZdZedZe ddZeddZedZedZ ddZddZdZdZdZdZ xZ!S)LoadaRepresents loader options which modify the state of a :class:`_query.Query` in order to affect how various mapped attributes are loaded. The :class:`_orm.Load` object is in most cases used implicitly behind the scenes when one makes use of a query option like :func:`_orm.joinedload`, :func:`.defer`, or similar. However, the :class:`_orm.Load` object can also be used directly, and in some cases can be useful. To use :class:`_orm.Load` directly, instantiate it with the target mapped class as the argument. This style of usage is useful when dealing with a :class:`_query.Query` that has multiple entities:: myopt = Load(MyClass).joinedload("widgets") The above ``myopt`` can now be used with :meth:`_query.Query.options`, where it will only take effect for the ``MyClass`` entity:: session.query(MyClass, MyOtherClass).options(myopt) One case where :class:`_orm.Load` is useful as public API is when specifying "wildcard" options that only take effect for a certain class:: session.query(Order).options(Load(Order).lazyload('*')) Above, all relationships on ``Order`` will be lazy-loaded, but other attributes on those descendant objects will load using their normal loader strategy. .. seealso:: :ref:`deferred_options` :ref:`deferred_loading_w_multiple` :ref:`relationship_loader_options` ct|}|j|_tj|_i|_d|_dSNF)r_path_registrypathr OrderedDictcontext local_optsis_class_strategy)selfentityinsps T/opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm/strategy_options.py__init__z Load.__init__Ls>v' ')) !&ch||}||_i|_i|_d|_|SN)__new__rrr _of_type)clsrloads r%for_existing_pathzLoad.for_existing_pathUs4{{3    r'c  |jdjrdSg}|jD]\\}} |dkrt |jj|D] \}}||urna jp jjd}|||}| |s jssg} |D]} t| tj r| | 2| jrdS| j r| | j _| j sJ| | j| r || dkr,|j r| |jn |jrdS| t|  jpdz jr-t fdt% jDndz|sdSt|S)NFloaderc.g|]}|j|fSr3)r ).0keyobjs r% z,Load._generate_cache_key..s5!"!"!"(+&)#.*=$>!"!"!"r')ris_aliased_classritemszipr+ _chop_path isinstancer string_typesappend is_propertyr6 is_mapperclass_tuplestrategyr sorted) r"r serializedr6 loader_path local_elemobj_elemendpointchoppedserialized_pathtokenr7s @r%_generate_cache_keyzLoad._generate_cache_key^sm 9Q< ( 5 '+|'9'9';';; ;  # S+h(+DINK(H(H7 7 $ HX--E.<<38=+<//+t<<    L"$$ = =E!%):;;='..u5555/=$uuu*='..uy9999$...'..u|<<<<&%(ob6I*I*I)%'..x????!2%$uu!!o..<-2/ #~ $E!"!"!"!"/5cn/E/E!"!"!""$   %4$$ $r'cdtt|}i|_|Sr))superr _generater )r"cloned __class__s r%rQzLoad._generates+tT"",,.. r'FNc2||ddSNT_processr"querys r% process_queryzLoad.process_querys eT"""""r'c2||ddSrrVrXs r%process_query_conditionallyz Load.process_query_conditionallys eU#####r'c|j}|rH|jD],\\}}}|||}| ||j||f<-dS|j|jdSr)) _current_pathrr:r< _attributesupdate)r"rYraiseerr current_pathrM start_pathr1chopped_start_paths r%rWz Load._processs*  3/3|/A/A/C/C L L+# V%)__Z%N%N"%1EKE%u.@&AB L L   $ $T\ 2 2 2 2 2r'Tc |j}d|_|rM|jsFt|trt jdt jd|jdt|tjr~| t}|}| ts|rF|rd|_ |r|d|}|r|j s |j|}||}||_|S|rt#|} n|j} t'| j|} |jx}} n#t,$r`} t|t.s@tjt jd|d| dt3|d | nYd} ~ nWd} ~ wwxYw#t,$rB} |r0tjt jd |d| d | nYd} ~ dSYd} ~ nd} ~ wwxYw||}nt5|rFt7j|j|d s$|r t jd|d|jddSnv|jx} } t7j|j|d sj|rft jd|d|jdt;|dkr1|jjr%|jj rd|dd|jjdnddSt'|ddr|j}t#|x}}|j | !|j"d}|j sHt7j#|j$j%|j$dd|t#|nd}t#|}|j | &|j"d||| |}||_n|| }|| '||jr|j }||_|S)Nz3Wildcard token cannot be followed by another entityzMapped attribute 'z#' does not refer to a mapped entityF:zExpected attribute "z" on z' to be a mapped attribute; instead got z object.)replace_contextzCan't find property named "z in this Query.r2z Attribute 'z' does not link from element ''z Attribute "z" does not link from element "".rz Did you mean to use z .of_type(z)?r+path_with_polymorphicT)aliased_use_mapper_path_existing_alias)(r+ has_entityr=rsa_exc ArgumentErrorproprr>endswithr r propagate_to_loadersr9parentrMrrr#getattrrBpropertyAttributeErrorr raise_typerorm_util$_entity_corresponds_to_use_path_impllenrA__name__ entity_pathgetrwith_polymorphicmapper base_mapperset _get_strategy)r"rattr for_strategy wildcard_keyraexisting_of_type default_token attr_str_nameentfound_propertyaeerrrsacext_info of_type_infoexistings r%_generate_pathzLoad._generate_paths0 =  DO $ .. *I**26)))> dD- . .@ " MM.99M M}}_--   605D-:&2llDD9D $9,<,M9;'78Dzz$''    ".//k sz400,0M9D>>%   %dN;;  "00$1==###tDzzzz!C -/ "   K,,3744>),  44444 8:DD d # #G "@ T"X   ..48DD$+++G  4 %)M 1D>@ T"X   ..!DD KKK $'t99q==$(K$9$1$(K$@$1=$(888T[-A-A-A!C!C &( !( $ 4tZ.. "]*1"++5<+D155L"9 0 +!2 3  $)-#/)0(9(9(9!B 'r{{H &**L"92Dz(+ , Dz  #  ( ( 6 6 6 ? $#D  s1F' D11 F;AFF G*(2G%%G*cd|jdS)NzLoad(strategy=))rDr"s r%__str__z Load.__str__Xs&*mmm55r'cf|.tt|}|Sr))rCrEr:)r"rDs r% _coerce_stratzLoad._coerce_strat[s,  VHNN$4$45566Hr'c td)NzHOnly 'unbound' loader options may be used with the Load.options() method)NotImplementedError)r"rvappliedbounds r%_apply_to_parentzLoad._apply_to_parent`s! $   r'ci}t|t }|rtd|D]}||||dS)aApply a series of options as sub-options to this :class:`_orm.Load` object. E.g.:: query = session.query(Author) query = query.options( joinedload(Author.book).options( load_only("summary", "excerpt"), joinedload(Book.citations).options( joinedload(Citation.author) ) ) ) :param \*opts: A series of loader option objects (ultimately :class:`_orm.Load` objects) which should be applied to the path specified by this :class:`_orm.Load` object. .. versionadded:: 1.3.6 .. seealso:: :func:`.defaultload` :ref:`relationship_loader_options` :ref:`deferred_loading_w_multiple` zMThe options() method is currently only supported for 'unbound' loader optionsN)r= _UnboundLoadrr)r"opts apply_cacheropts r%optionsz Load.optionsfsqB t\222  %/  ; ;C  {E : : : : ; ;r'c||}||_|||d}|j|_|j|_dx|_|_|j|_dS)N relationshipF)rru_clone_for_bind_strategyrr+r!)r"rrDrurRs r%set_relationship_strategyzLoad.set_relationship_strategysi%%h//$8!..tX~NNK   '!Y-NN!YN  " &@@BB  ""L #0 #     ,     r'c|j}|dtj|dd|d<|j|d<|S)Nr)r1r)__dict__copyrserialize_context_dictr serializer"ds r% __getstate__zLoad.__getstate__s\ M    Y< #'>) kAiLI''))& r'c|j|tj|j|_|j tj|j|_dSdSr))rr`r deserializerrdeserialize_context_dict)r"states r% __setstate__zLoad.__setstate__sT U### ,TY77 < #'@NNDLLL $ #r'cd}tt||jD]\}\}}t|tjrC|dkr!|dtzr|cS|dtkr||j krdS||urjt|tr$|j r|j r| |rdS||dzdSNr2r0rfz relationship:r) enumerater;rr=rr>rtr r r6rrAisa)r"to_chopric_tokenp_tokens r%r<zLoad._chop_paths %.s7DI/F/F%G%G   !A!'4#455 66g..s^/CDD6"NNNGOOEEE7;..44'!!7N33 % % KK((   ttq1uwwr')Tr)FN)TF)"r __module__ __qualname____doc__r& classmethodr.rNrQrr!rDrur+rZr\rWrrrrrrrrrrrrrrrr< __classcell__)rSs@r%rr!s((T'''[D%D%D%L LH H###$$$333@DWWWWr666    (;(;[(;T37 @ @ @[ @///[///[/''['CG. < < < <4OOO        r'rc~eZdZdZdZdZdZdZddZdZ d Z d Z d Z e d Zd ZddZdZdZdZdS)ra<Represent a loader option that isn't tied to a root entity. The loader option will produce an entity-linked :class:`_orm.Load` object when it is passed :meth:`_query.Query.options`. This provides compatibility with the traditional system of freestanding options, e.g. ``joinedload('x.y.z')``. c0d|_g|_i|_dS)Nr3)r_to_bindr rs r%r&z_UnboundLoad.__init__1s  r'Fcd}|jD]q}t|j|jD] \}}||urnJ ||jdgddd}|r#||}|durdS|r||z }r|sdS|S)Nr3r0F)rr;r _bind_loaderrN)r"rrFvalrHval_elemrc_keys r%rNz _UnboundLoad._generate_cache_key8s = , ,C(+DIsx(@(@ , ,$ HX--E.&& ! ~tT5II,33D99E~~$uu,"e+  4 r'cH|j|d|_dSr))rr?rs r%rz_UnboundLoad._set_path_strategyKs% T""" r'Nc|vr|S|j|}||<|j|_|jr|jd}t |t jr@|tr&| dddztz}| j|jddz||jd|j |j ksJ|j |j ksJ|j|jksJfdD}j|_|j||j|j|S)Nr2rfr0c@h|]}|Sr3)r)r5elemrrrvto_binds r% z0_UnboundLoad._apply_to_parent..ns=     ! !&'5' B B   r')rrQrDrr=rr>rtr splitr rrur!rextendr r`)r"rvrrrrRr new_to_binds ```` r%rz_UnboundLoad._apply_to_parentRs 7??4= ?mG!! - 9 9R=D$ 122 Bt}}88 Bzz#q)C//A  ! ! di"o-tT]D    *d.GGGGG'4+AAAAA"d&77777          !/{+++  111 r'c|rCt|tjr)|ttfvr|tkrd|_|d|}|r&t |dr|js |dd}|r||fz}||_|S)NFrfr2r0) r=rr>r r rurr!r)r"rrrrs r%rz_UnboundLoad._generate_pathxs  24!233 2.999~%%,1)*llDD1D  $T"X.. t7M ":D  "4'>D  r'cv|j}||jd|d<|S)NT)filter_aliased_classr)rr_serialize_pathrrs r%rz_UnboundLoad.__getstate__s8 M   (((NN& r'cbg}|dD]}t|tr^t|dkr|\}}d}n|\}}}t||}|r||}||u||t||d<||_dS)Nrr)r=rCr~rwof_typer?r)r"rretr6r,propkeyrrss r%rz_UnboundLoad.__setstate__s= C#u%% s88q==#&LC"GG,/)C'sG,,1<<00D 4     3c f  r'c|jd}|jD]L}||vrF|||d|jD|j|j|MdS)N_unbound_load_dedupescg|] }|j Sr3) entity_zeror5rs r%r8z)_UnboundLoad._process..sGGGS_GGGr')r_raddr_mapper_entitiesr^)r"rYradedupesrs r%rWz_UnboundLoad._processs#$;<=  C'!! C     GG0FGGG'%   r'ct}dfd|D}|ddD]+}d|_|r |||fi|}||},|||dfi|}d|_|S)Nct|tjrO|tkrtfS|dtzr |dd}|dS|fS)N.r)r=rr>r r startswithrr6s r% _split_keyz+_UnboundLoad._from_keys.._split_keysh#t011 /))*,,^^C/$9::"abb'Cyy~~%v r'c0g|]}|D]}|Sr3r3)r5r6rMrs r%r8z+_UnboundLoad._from_keys..s.IIICIIeIIIIr'r0r2TF)r_is_chain_link defaultload) r,methkeyschainedkwr all_tokensrMrs @r% _from_keysz_UnboundLoad._from_keyssnn   JIIItIII "% - -E"&C  -d3,,,,ooe,,d3 2--"--" r'cd}tt||D]\}\}\}}t|tjrD|dkr!|dtzr|cS|dtkr||j krdSit|tr;|j |us/|j |ur)|j j r|j |sdS|dz }||dSr)rr;pairsr=rr>rtr r r6r rx _parententityrAr)r"rrrrp_entityp_props r%r<z_UnboundLoad._chop_paths# 09  & &1 1    ,A,+(F'4#455 66g..s^/CDD6"NNNGOOEEE6:--44G^44 #611)99#1;: '488BB:  44 FAqrr{r'cg}|D]}t|trw|rH|jrAt|jjr(||jj|jdfa||jj|j|jft|tr(||jj|jdf|||Sr)) r=rr+rr9r? _parentmapperrBr6r )r"rrrrMs r%rz_UnboundLoad._serialize_paths " "E%!344 "(   //@  JJ 3 :EItLMMMMJJ,3UYOE>22 " E/6 4HIIII 5!!!! r'c |j}|jr|r ||dfz }|r|||}|sdS|d}t|tjr||||}nzt|tr%|j}| |||j |}n@|jr%t|rt|}||vrd}ntjd|sdS|} t| } ||| _n| j}|j| _|j| _|j| _| j} | jsSt'|D]C\} }| | j|| t+|dz kr|jndd|sdSD| j|j| js| jjr | jj} n| j} | jr<| D]&} | || |j |j'n$| || |j |j| S)a]Convert from an _UnboundLoad() object into a Load() object. The _UnboundLoad() uses an informal "path" and does not necessarily refer to a lead entity as it may use string tokens. The Load() OTOH refers to a complete path. This method reconciles from a given Query into a Load. Example:: query = session.query(User).options( joinedload("orders").joinedload("items")) The above options will be an _UnboundLoad object along the lines of (note this is not the exact API of _UnboundLoad):: _UnboundLoad( _to_bind=[ _UnboundLoad(["orders"], {"lazy": "joined"}), _UnboundLoad(["orders", "items"], {"lazy": "joined"}), ] ) After this method, we get something more like this (again this is not exact API):: Load( User, (User, User.orders.property)) Load( User, (User, User.orders.property, Order, Order.items.property)) r0Nz6mapper option expects string key or list of attributesrr)rr!r<r=rr>_find_entity_basestringr rx_find_entity_prop_comparatorr rrrqrrrrrDrrrr~r r`rprvrrrr)r"entitiesrbrrarcrMr#rs path_elementr1ridxrs r%rz_UnboundLoad._bind_loadersHY  ! )l ) 8A;. (J  C\BBJ 41  eT. / / 11(E8LLFF ~ . . >D66$ 3XFF # (8(?(? U^^FX%%&K   F l##  $FNNnG-"/#'#9 {' ' 33   U,,K%(C OOa,?%?%?DMMT FF   111' )FK,B )#[/NN#[N  " &@@BB  $$ $ 33#0 %    //, !    r'c t|r|}nt|}|D]}tj||r|cS|rt |s:t jdtjt|d|dt jd|dd d|DddS) Nz@Query has only expression-based entities, which do not apply to z ""zMapped attribute "zA" does not apply to any of the root entities in this query, e.g. , c34K|]}t|VdSr)str)r5xs r% z<_UnboundLoad._find_entity_prop_comparator..s(*D*Da3q66*D*D*D*D*D*Dr'zV. Please specify the full path from one of the root entities to the target attribute. ) rrr|_entity_corresponds_tolistrqrrrclsname_as_plain_namer{join)r"rrsrra searchforrs r%rz)_UnboundLoad._find_entity_prop_comparator~s V $ $ 1II(00I  C.sI>>    H~~ .. 5d4jjAAAA444I !..  44*D*D8*D*D*D!D!D!D!D Ftr'c |dtzrxtt|dkrW|rUt jddd|Dddd|Ddn|trd }|D]}|cS|rt jd |d dS) NrfrzMCan't apply wildcard ('*') or load_only() loader option to multiple entities rc34K|]}t|VdSr)rrs r%rz7_UnboundLoad._find_entity_basestring..s(%C%C3c#hh%C%C%C%C%C%Cr'z?. Specify loader options for each entity individually, such as c3 K|] }d|zV dS)zLoad(%s).some_option('*')Nr3rs r%rz7_UnboundLoad._find_entity_basestring..s;&&$'!>#/ 0 0 4>>""a''  .. !II%C%C(%C%C%CCCCC II&&+3&&&    ^^N + + H  CJJJ **:?%%B tr'r)F)rrrrr&rrNrrrrrrWrr r<rrrrr3r'r%rr&s N&$$$$L  &   [>6(AAAF8     r'rc&eZdZdZdZdZdZdS) loader_optioncdSr)r3rs r%r&zloader_option.__init__s r'c|jx|_}||_tt|rt d|zt t|||S)Nz#Load class already has a %s method.)rnamefnhasattrr TypeErrorsetattr)r"r-r,s r%__call__zloader_option.__call__sU;& D 4   LATJKK KdB r'cf||_|jj}dd|jiz|j_||_|S)NzProduce a new :class:`_orm.Load` object with the :func:`_orm.%(name)s` option applied. See :func:`_orm.%(name)s` for usage examples. r,) _unbound_fnr-rr,)r"r-fn_docs r%_add_unbound_fnzloader_option._add_unbound_fns? DI    r'cdd|jiz|_tjddd|jizd|}||_|S)Na}Produce a standalone "all" option for :func:`_orm.%(name)s`. .. deprecated:: 0.9 The :func:`_orm.%(name)s_all` function is deprecated, and will be removed in a future release. Please use method chaining with :func:`_orm.%(name)s` instead, as in:: session.query(MyClass).options( %(name)s("someattribute").%(name)s("anotherattribute") ) r,z0.9zThe :func:`.%(name)s_all` function is deprecated, and will be removed in a future release. Please use method chaining with :func:`.%(name)s` insteadF)add_deprecation_to_docstring)r,rr deprecated_unbound_all_fn)r"r-s r%_add_unbound_all_fnz!loader_option._add_unbound_all_fnsr  DI    T_  (+149*= >*/     " r'N)rrrr&r1r5r:r3r'r%r)r)sP      r'r)Nc|,t|tst|}|j}n,t |ddrt|j}|j}||ddid}||jd<|S)aIndicate that the given attribute should be eagerly loaded from columns stated manually in the query. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. The option is used in conjunction with an explicit join that loads the desired rows, i.e.:: sess.query(Order).\ join(Order.user).\ options(contains_eager(Order.user)) The above query would join from the ``Order`` entity to its related ``User`` entity, and the returned ``Order`` objects would have the ``Order.user`` attribute pre-populated. It may also be used for customizing the entries in an eagerly loaded collection; queries will normally want to use the :meth:`_query.Query.populate_existing` method assuming the primary collection of parent objects may already have been loaded:: sess.query(User).\ join(User.addresses).\ filter(Address.email_address.like('%@aol.com')).\ options(contains_eager(User.addresses)).\ populate_existing() See the section :ref:`contains_eager` for complete usage details. .. seealso:: :ref:`loading_toplevel` :ref:`contains_eager` Nr+lazyjoinedF)rueager_from_alias)r=rr selectablerwr+rr )loadoptraliasinfootrRs r%contains_eagerrDsN %%% $5>>DOE z4 ( ( T] # #   . . vx u/F-2F() Mr'c^ttj|d|SrU)rr rDrrs r%rDrD-s* >> $ $#T4  r'cp||ddd}|ddddddi|S)aQIndicate that for a particular entity, only the given list of column-based attribute names should be loaded; all others will be deferred. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. Example - given a class ``User``, load only the ``name`` and ``fullname`` attributes:: session.query(User).options(load_only("name", "fullname")) Example - given a relationship ``User.addresses -> Address``, specify subquery loading for the ``User.addresses`` collection, but on each ``Address`` object load only the ``email_address`` attribute:: session.query(User).options( subqueryload("addresses").load_only("email_address") ) For a :class:`_query.Query` that has multiple entities, the lead entity can be specifically referred to using the :class:`_orm.Load` constructor:: session.query(User, Address).join(User.addresses).options( Load(User).load_only("name", "fullname"), Load(Address).load_only("email_address") ) .. note:: This method will still load a :class:`_schema.Column` even if the column property is defined with ``deferred=True`` for the :func:`.column_property` function. .. versionadded:: 0.9.0 FTdeferred instrument* undefer_pksr)r@rrRs r% load_onlyrN4s\L ( ( E66F  $d 3 3mT5J Mr'c.tj|Sr))rrN)rs r%rNrNcs #<>> #U ++r'cN||ddi}| ||jd<|S)a? Indicate that the given attribute should be loaded using joined eager loading. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. examples:: # joined-load the "orders" collection on "User" query(User).options(joinedload(User.orders)) # joined-load Order.items and then Item.keywords query(Order).options( joinedload(Order.items).joinedload(Item.keywords)) # lazily load Order.items, but when Items are loaded, # joined-load the keywords collection query(Order).options( lazyload(Order.items).joinedload(Item.keywords)) :param innerjoin: if ``True``, indicates that the joined eager load should use an inner join instead of the default of left outer join:: query(Order).options(joinedload(Order.user, innerjoin=True)) In order to chain multiple eager joins together where some may be OUTER and others INNER, right-nested joins are used to link them:: query(A).options( joinedload(A.bs, innerjoin=False). joinedload(B.cs, innerjoin=True) ) The above query, linking A.bs via "outer" join and B.cs via "inner" join would render the joins as "a LEFT OUTER JOIN (b JOIN c)". When using older versions of SQLite (< 3.7.16), this form of JOIN is translated to use full subqueries as this syntax is otherwise not directly supported. The ``innerjoin`` flag can also be stated with the term ``"unnested"``. This indicates that an INNER JOIN should be used, *unless* the join is linked to a LEFT OUTER JOIN to the left, in which case it will render as LEFT OUTER JOIN. For example, supposing ``A.bs`` is an outerjoin:: query(A).options( joinedload(A.bs). joinedload(B.cs, innerjoin="unnested") ) The above join will render as "a LEFT OUTER JOIN b LEFT OUTER JOIN c", rather than as "a LEFT OUTER JOIN (b JOIN c)". .. note:: The "unnested" flag does **not** affect the JOIN rendered from a many-to-many association table, e.g. a table configured as :paramref:`_orm.relationship.secondary`, to the target table; for correctness of results, these joins are always INNER and are therefore right-nested if linked to an OUTER join. .. versionchanged:: 1.0.0 ``innerjoin=True`` now implies ``innerjoin="nested"``, whereas in 0.9 it implied ``innerjoin="unnested"``. In order to achieve the pre-1.0 "unnested" inner join behavior, use the value ``innerjoin="unnested"``. See :ref:`migration_3008`. .. note:: The joins produced by :func:`_orm.joinedload` are **anonymously aliased**. The criteria by which the join proceeds cannot be modified, nor can the :class:`_query.Query` refer to these joins in any way, including ordering. See :ref:`zen_of_eager_loading` for further detail. To produce a specific SQL JOIN which is explicitly available, use :meth:`_query.Query.join`. To combine explicit JOINs with eager loading of collections, use :func:`_orm.contains_eager`; see :ref:`contains_eager`. .. seealso:: :ref:`loading_toplevel` :ref:`joined_eager_loading` r<r=N innerjoin)rr )r@rrQr1s r% joinedloadrRhs7p . .tfh5G H HF)2+& Mr'cPttj|d|Srrr rRrFs r%rRrRs  " "<#:D% L LLr'cPttj|d|SrUrTrFs r%joinedload_allrVs  " "<#:D$ K KKr'c2||ddiS)aIndicate that the given attribute should be loaded using subquery eager loading. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. examples:: # subquery-load the "orders" collection on "User" query(User).options(subqueryload(User.orders)) # subquery-load Order.items and then Item.keywords query(Order).options( subqueryload(Order.items).subqueryload(Item.keywords)) # lazily load Order.items, but when Items are loaded, # subquery-load the keywords collection query(Order).options( lazyload(Order.items).subqueryload(Item.keywords)) .. seealso:: :ref:`loading_toplevel` :ref:`subquery_eager_loading` r<subqueryrr@rs r% subqueryloadr[s<  , ,TFJ3G H HHr'cPttj|diSrrr r[rs r%r[r[  " "<#  , ,TFJ3G H HHr'cPttj|diSrrr rer^s r%rerer_r'cPttj|diSrUrgr^s r%selectinload_allri"rbr'c2||ddiS)a Indicate that the given attribute should be loaded using "lazy" loading. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. .. seealso:: :ref:`loading_toplevel` :ref:`lazy_loading` r<selectrYrZs r%lazyloadrl's  , ,TFH3E F FFr'cPttj|diSrrr rlr^s r%rlrl9s  " "<#8$r J JJr'cPttj|diSrUrnr^s r% lazyload_allrp>s  " "<#8$b I IIr'c6||ddi}|S)aIndicate that the given attribute should be loaded using an immediate load with a per-attribute SELECT statement. The :func:`.immediateload` option is superseded in general by the :func:`.selectinload` option, which performs the same task more efficiently by emitting a SELECT for all loaded objects. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. .. seealso:: :ref:`loading_toplevel` :ref:`selectin_eager_loading` r< immediaterY)r@rr1s r% immediateloadrsCs#& . .tfk5J K KF Mr'cPttj|diSr)rr rsr^s r%rsrsZs  " "<#=tUB O OOr'c2||ddiS)aIndicate that the given relationship attribute should remain unloaded. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. :func:`_orm.noload` applies to :func:`_orm.relationship` attributes; for column-based attributes, see :func:`_orm.defer`. .. seealso:: :ref:`loading_toplevel` r<noloadrYrZs r%rvrv_s  , ,TFH3E F FFr'cPttj|diSr)rr rvr^s r%rvrvrs  " "<#6eR H HHr'Fc:||d|rdndiS)aIndicate that the given relationship attribute should disallow lazy loads. A relationship attribute configured with :func:`_orm.raiseload` will raise an :exc:`~sqlalchemy.exc.InvalidRequestError` upon access. The typical way this is useful is when an application is attempting to ensure that all relationship attributes that are accessed in a particular context would have been already loaded via eager loading. Instead of having to read through SQL logs to ensure lazy loads aren't occurring, this strategy will cause them to raise immediately. :param sql_only: if True, raise only if the lazy load would emit SQL, but not if it is only checking the identity map, or determining that the related value should just be None due to missing keys. When False, the strategy will raise for all varieties of lazyload. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. :func:`_orm.raiseload` applies to :func:`_orm.relationship` attributes only. .. versionadded:: 1.1 .. seealso:: :ref:`loading_toplevel` :ref:`prevent_lazy_with_raiseload` r< raise_on_sqlraiserY)r@rsql_onlys r% raiseloadr|ws0B  , , v>~~w?  r'cPttj|d|Sr)rr r|rFs r%r|r|s  " "<#94 K KKr'c.||dS)a:Indicate an attribute should load using its default loader style. This method is used to link to other loader options further into a chain of attributes without altering the loader style of the links along the chain. For example, to set joined eager loading for an element of an element:: session.query(MyClass).options( defaultload(MyClass.someattribute). joinedload(MyOtherClass.someotherattribute) ) :func:`.defaultload` is also useful for setting column-level options on a related class, namely that of :func:`.defer` and :func:`.undefer`:: session.query(MyClass).options( defaultload(MyClass.someattribute). defer("some_column"). undefer("some_other_column") ) .. seealso:: :meth:`_orm.Load.options` - allows for complex hierarchical loader option structures with less verbosity than with individual :func:`.defaultload` directives. :ref:`relationship_loader_options` :ref:`deferred_loading_w_multiple` NrYrZs r%rrsD  , ,T4 8 88r'cPttj|diSr)rr rr^s r%rrs  " "<#;T5" M MMr'c6||fdddS)aIndicate that the given column-oriented attribute should be deferred, e.g. not loaded until accessed. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. e.g.:: from sqlalchemy.orm import defer session.query(MyClass).options( defer("attribute_one"), defer("attribute_two")) session.query(MyClass).options( defer(MyClass.attribute_one), defer(MyClass.attribute_two)) To specify a deferred load of an attribute on a related class, the path can be specified one token at a time, specifying the loading style for each link along the chain. To leave the loading style for a link unchanged, use :func:`_orm.defaultload`:: session.query(MyClass).options(defaultload("someattr").defer("some_column")) A :class:`_orm.Load` object that is present on a certain path can have :meth:`_orm.Load.defer` called multiple times, each will operate on the same parent entity:: session.query(MyClass).options( defaultload("someattr"). defer("some_column"). defer("some_other_column"). defer("another_column") ) :param key: Attribute to be deferred. :param \*addl_attrs: This option supports the old 0.8 style of specifying a path as a series of attributes, which is now superseded by the method-chained style. .. deprecated:: 0.9 The \*addl_attrs on :func:`_orm.defer` is deprecated and will be removed in a future release. Please use method chaining in conjunction with defaultload() to indicate a path. .. seealso:: :ref:`deferred` :func:`_orm.undefer` TrHrMr@r6s r%deferrs,v  & & T66  r'c|rtjdttj|f|zdiS)Nz}The *addl_attrs on orm.defer is deprecated. Please use method chaining in conjunction with defaultload() to indicate a path.F)rwarn_deprecatedrr rr6 addl_attrss r%rr sQ       " "SFZ/  r'c6||fdddS)agIndicate that the given column-oriented attribute should be undeferred, e.g. specified within the SELECT statement of the entity as a whole. The column being undeferred is typically set up on the mapping as a :func:`.deferred` attribute. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. Examples:: # undefer two columns session.query(MyClass).options(undefer("col1"), undefer("col2")) # undefer all columns specific to a single class using Load + * session.query(MyClass, MyOtherClass).options( Load(MyClass).undefer("*")) # undefer a column on a related object session.query(MyClass).options( defaultload(MyClass.items).undefer('text')) :param key: Attribute to be undeferred. :param \*addl_attrs: This option supports the old 0.8 style of specifying a path as a series of attributes, which is now superseded by the method-chained style. .. deprecated:: 0.9 The \*addl_attrs on :func:`_orm.undefer` is deprecated and will be removed in a future release. Please use method chaining in conjunction with defaultload() to indicate a path. .. seealso:: :ref:`deferred` :func:`_orm.defer` :func:`_orm.undefer_group` FTrHrMrs r%undeferrs,X  & & U$77  r'c|rtjdttj|f|zdiS)NzThe *addl_attrs on orm.undefer is deprecated. Please use method chaining in conjunction with defaultload() to indicate a path.F)rrrr rrs r%rrJsQ       " "sfz15"  r'c>|ddd|zdidS)aIndicate that columns within the given deferred group name should be undeferred. The columns being undeferred are set up on the mapping as :func:`.deferred` attributes and include a "group" name. E.g:: session.query(MyClass).options(undefer_group("large_attrs")) To undefer a group of attributes on a related entity, the path can be spelled out using relationship loader options, such as :func:`_orm.defaultload`:: session.query(MyClass).options( defaultload("someattr").undefer_group("large_attrs")) .. versionchanged:: 0.9.0 :func:`_orm.undefer_group` is now specific to a particular entity load path. .. seealso:: :ref:`deferred` :func:`_orm.defer` :func:`_orm.undefer` rKNzundefer_group_%sT)rrM)r@r,s r% undefer_grouprWs5>  & & T&-t4 '  r'cDt|Sr))rr)r,s r%rr{s >> ' ' - --r'c~tjt|}||fddid|iS)aApply an ad-hoc SQL expression to a "deferred expression" attribute. This option is used in conjunction with the :func:`_orm.query_expression` mapper-level construct that indicates an attribute which should be the target of an ad-hoc SQL expression. E.g.:: sess.query(SomeClass).options( with_expression(SomeClass.x_y_expr, SomeClass.x + SomeClass.y) ) .. versionadded:: 1.2 :param key: Attribute to be undeferred. :param expr: SQL expression to be applied to the attribute. .. note:: the target attribute is populated only if the target object is **not currently loaded** in the current :class:`_orm.Session` unless the :meth:`_query.Query.populate_existing` method is used. Please refer to :ref:`mapper_querytime_expression` for complete usage details. .. seealso:: :ref:`mapper_querytime_expression` query_expressionTrr)sql_expr_labeledrr)r@r6rs r%with_expressionrsOB"#7 #C#CDDJ  & & #T*, 1K '  r'cVttj|fdd|iS)NFr)rr r)r6rs r%rrs-  " "$sfelJ5O  r'c |ddidttd|Dti|S)a~Indicate an eager load should take place for all attributes specific to a subclass. This uses an additional SELECT with IN against all matched primary key values, and is the per-query analogue to the ``"selectin"`` setting on the :paramref:`.mapper.polymorphic_load` parameter. .. versionadded:: 1.2 .. seealso:: :ref:`polymorphic_selectin` selectinload_polymorphicTrc34K|]}t|VdSr)r)r5r,s r%rz'selectin_polymorphic..s(88 888888r'rr)rrCrEid)r@classess r%selectin_polymorphicrsc   #T* 88888bAAA  Nr'ct}d|_t|f|_|||SrU)rr!rrr)base_clsruls r%rrs> BBx  "BGG$$$ Ir'r)r')7rrkrr| attributesrbaserrrr interfacesr r r path_registryr r rrrrrqrsqlrrsql.baserrrrobjectr)rDr5rNrRr:rVr[rarerirlrprsrvr|rrrrrrr3r'r%rs******""""""######"""""" $$$$$$&&&&&&&&&&&&))))))******''''''((((((&&&&&&((((((""""""!!!!!!B B B B B :|B B B JTTTTT4TTTn 66666F666r3333l  +++\ ,,,ZZZZz MMM LL LIII@OOO!NN"!NIIIBOOO!NN"!NGGG" KKK JJJ,PPPGGG$III""""J LLL!9!9!9H NNN<<<~   ---`       F...$$$N !  4%&%r'