~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to doc/orm/internals.html

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2011-08-01 23:18:16 UTC
  • mfrom: (1.4.15 upstream) (16.1.14 experimental)
  • Revision ID: james.westby@ubuntu.com-20110801231816-6lx797pi3q1fpqst
Tags: 0.7.2-1
* New upstream release
* Bump minimum required python-mako version to 0.4.1 (closes: 635898)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
 
 
4
<html>
 
5
    <head>
 
6
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
7
        
 
8
        <title>
 
9
                ORM Internals
 
10
             &mdash; SQLAlchemy 0.7 Documentation</title>
 
11
        
 
12
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
 
13
    <link rel="stylesheet" href="../_static/docs.css" type="text/css" />
 
14
 
 
15
    <script type="text/javascript">
 
16
      var DOCUMENTATION_OPTIONS = {
 
17
          URL_ROOT:    '../',
 
18
          VERSION:     '0.7.2',
 
19
          COLLAPSE_MODINDEX: false,
 
20
          FILE_SUFFIX: '.html'
 
21
      };
 
22
    </script>
 
23
        <script type="text/javascript" src="../_static/jquery.js"></script>
 
24
        <script type="text/javascript" src="../_static/underscore.js"></script>
 
25
        <script type="text/javascript" src="../_static/doctools.js"></script>
 
26
    <script type="text/javascript" src="../_static/init.js"></script>
 
27
    <link rel="index" title="Index" href="../genindex.html" />
 
28
    <link rel="search" title="Search" href="../search.html" />
 
29
        <link rel="copyright" title="Copyright" href="../copyright.html" />
 
30
    <link rel="top" title="SQLAlchemy 0.7 Documentation" href="../index.html" />
 
31
        <link rel="up" title="SQLAlchemy ORM" href="index.html" />
 
32
        <link rel="next" title="SQLAlchemy Core" href="../core/index.html" />
 
33
        <link rel="prev" title="ORM Exceptions" href="exceptions.html" />
 
34
 
 
35
    </head>
 
36
    <body>
 
37
        
 
38
 
 
39
 
 
40
 
 
41
<h1>SQLAlchemy 0.7 Documentation</h1>
 
42
 
 
43
<div id="search">
 
44
Search:
 
45
<form class="search" action="../search.html" method="get">
 
46
  <input type="text" name="q" size="18" /> <input type="submit" value="Search" />
 
47
  <input type="hidden" name="check_keywords" value="yes" />
 
48
  <input type="hidden" name="area" value="default" />
 
49
</form>
 
50
</div>
 
51
 
 
52
<div class="versionheader">
 
53
    Release: <span class="versionnum">0.7.2</span> | Release Date: July 31, 2011
 
54
</div>
 
55
<div class="clearboth"></div>
 
56
 
 
57
<div id="topnav">
 
58
    <div id="pagecontrol">
 
59
        <ul>
 
60
            <li>Prev:
 
61
            <a href="exceptions.html" title="previous chapter">ORM Exceptions</a>
 
62
            </li>
 
63
            <li>Next:
 
64
            <a href="../core/index.html" title="next chapter">SQLAlchemy Core</a>
 
65
            </li>
 
66
 
 
67
        <li>
 
68
            <a href="../contents.html">Table of Contents</a> |
 
69
            <a href="../genindex.html">Index</a>
 
70
            | <a href="../_sources/orm/internals.txt">view source
 
71
        </li>
 
72
        </ul>
 
73
    </div>
 
74
    <div id="navbanner">
 
75
        <a class="totoc" href="../index.html">SQLAlchemy 0.7 Documentation</a>
 
76
                » <a href="index.html" title="SQLAlchemy ORM">SQLAlchemy ORM</a>
 
77
        » 
 
78
                ORM Internals
 
79
             
 
80
 
 
81
        <h2>
 
82
            
 
83
                ORM Internals
 
84
            
 
85
        </h2>
 
86
    </div>
 
87
    <div class="clearboth"></div>
 
88
</div>
 
89
 
 
90
<div class="document">
 
91
    <div class="body">
 
92
        
 
93
<div class="section" id="orm-internals">
 
94
<span id="orm-internal-toplevel"></span><h1>ORM Internals<a class="headerlink" href="#orm-internals" title="Permalink to this headline">¶</a></h1>
 
95
<p>Some key internal constructs are listed here.</p>
 
96
<dl class="class">
 
97
<dt id="sqlalchemy.orm.instrumentation.ClassManager">
 
98
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.instrumentation.</tt><tt class="descname">ClassManager</tt><big>(</big><em>class_</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.instrumentation.ClassManager" title="Permalink to this definition">¶</a></dt>
 
99
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">dict</span></tt></p>
 
100
<p>tracks state information at the class level.</p>
 
101
<dl class="method">
 
102
<dt id="sqlalchemy.orm.instrumentation.ClassManager.dispose">
 
103
<tt class="descname">dispose</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.orm.instrumentation.ClassManager.dispose" title="Permalink to this definition">¶</a></dt>
 
104
<dd><p>Dissasociate this manager from its class.</p>
 
105
</dd></dl>
 
106
 
 
107
<dl class="method">
 
108
<dt id="sqlalchemy.orm.instrumentation.ClassManager.has_parent">
 
109
<tt class="descname">has_parent</tt><big>(</big><em>state</em>, <em>key</em>, <em>optimistic=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.instrumentation.ClassManager.has_parent" title="Permalink to this definition">¶</a></dt>
 
110
<dd><p>TODO</p>
 
111
</dd></dl>
 
112
 
 
113
<dl class="method">
 
114
<dt id="sqlalchemy.orm.instrumentation.ClassManager.manage">
 
115
<tt class="descname">manage</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.orm.instrumentation.ClassManager.manage" title="Permalink to this definition">¶</a></dt>
 
116
<dd><p>Mark this instance as the manager for its class.</p>
 
117
</dd></dl>
 
118
 
 
119
<dl class="attribute">
 
120
<dt id="sqlalchemy.orm.instrumentation.ClassManager.original_init">
 
121
<tt class="descname">original_init</tt><a class="headerlink" href="#sqlalchemy.orm.instrumentation.ClassManager.original_init" title="Permalink to this definition">¶</a></dt>
 
122
<dd><p>x.__init__(...) initializes x; see help(type(x)) for signature</p>
 
123
</dd></dl>
 
124
 
 
125
<dl class="method">
 
126
<dt id="sqlalchemy.orm.instrumentation.ClassManager.state_getter">
 
127
<tt class="descname">state_getter</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.orm.instrumentation.ClassManager.state_getter" title="Permalink to this definition">¶</a></dt>
 
128
<dd><p>Return a (instance) -&gt; InstanceState callable.</p>
 
129
<p>&#8220;state getter&#8221; callables should raise either KeyError or
 
130
AttributeError if no InstanceState could be found for the
 
131
instance.</p>
 
132
</dd></dl>
 
133
 
 
134
<dl class="method">
 
135
<dt id="sqlalchemy.orm.instrumentation.ClassManager.unregister">
 
136
<tt class="descname">unregister</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.orm.instrumentation.ClassManager.unregister" title="Permalink to this definition">¶</a></dt>
 
137
<dd><p>remove all instrumentation established by this ClassManager.</p>
 
138
</dd></dl>
 
139
 
 
140
</dd></dl>
 
141
 
 
142
<dl class="class">
 
143
<dt id="sqlalchemy.orm.properties.ColumnProperty">
 
144
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.properties.</tt><tt class="descname">ColumnProperty</tt><big>(</big><em>*columns</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.ColumnProperty" title="Permalink to this definition">¶</a></dt>
 
145
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.orm.interfaces.StrategizedProperty</span></tt></p>
 
146
<p>Describes an object attribute that corresponds to a table column.</p>
 
147
<p>Public constructor is the <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.column_property" title="sqlalchemy.orm.column_property"><tt class="xref py py-func docutils literal"><span class="pre">orm.column_property()</span></tt></a> function.</p>
 
148
<dl class="method">
 
149
<dt id="sqlalchemy.orm.properties.ColumnProperty.__init__">
 
150
<tt class="descname">__init__</tt><big>(</big><em>*columns</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.ColumnProperty.__init__" title="Permalink to this definition">¶</a></dt>
 
151
<dd><p>Construct a ColumnProperty.</p>
 
152
<p>Note the public constructor is the <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.column_property" title="sqlalchemy.orm.column_property"><tt class="xref py py-func docutils literal"><span class="pre">orm.column_property()</span></tt></a> function.</p>
 
153
<table class="docutils field-list" frame="void" rules="none">
 
154
<col class="field-name" />
 
155
<col class="field-body" />
 
156
<tbody valign="top">
 
157
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
158
<li><strong>*columns</strong> &#8211; The list of <cite>columns</cite> describes a single
 
159
object property. If there are multiple tables joined
 
160
together for the mapper, this list represents the equivalent
 
161
column as it appears across each table.</li>
 
162
<li><strong>group</strong> &#8211; </li>
 
163
<li><strong>deferred</strong> &#8211; </li>
 
164
<li><strong>comparator_factory</strong> &#8211; </li>
 
165
<li><strong>descriptor</strong> &#8211; </li>
 
166
<li><strong>extension</strong> &#8211; </li>
 
167
</ul>
 
168
</td>
 
169
</tr>
 
170
</tbody>
 
171
</table>
 
172
</dd></dl>
 
173
 
 
174
</dd></dl>
 
175
 
 
176
<dl class="class">
 
177
<dt id="sqlalchemy.orm.descriptor_props.CompositeProperty">
 
178
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.descriptor_props.</tt><tt class="descname">CompositeProperty</tt><big>(</big><em>class_</em>, <em>*attrs</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.descriptor_props.CompositeProperty" title="Permalink to this definition">¶</a></dt>
 
179
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.orm.descriptor_props.DescriptorProperty</span></tt></p>
 
180
<dl class="method">
 
181
<dt id="sqlalchemy.orm.descriptor_props.CompositeProperty.do_init">
 
182
<tt class="descname">do_init</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.orm.descriptor_props.CompositeProperty.do_init" title="Permalink to this definition">¶</a></dt>
 
183
<dd><p>Initialization which occurs after the <a class="reference internal" href="#sqlalchemy.orm.descriptor_props.CompositeProperty" title="sqlalchemy.orm.descriptor_props.CompositeProperty"><tt class="xref py py-class docutils literal"><span class="pre">CompositeProperty</span></tt></a> 
 
184
has been associated with its parent mapper.</p>
 
185
</dd></dl>
 
186
 
 
187
<dl class="method">
 
188
<dt id="sqlalchemy.orm.descriptor_props.CompositeProperty.get_history">
 
189
<tt class="descname">get_history</tt><big>(</big><em>state</em>, <em>dict_</em>, <em>passive=&lt;symbol 'PASSIVE_OFF&gt;</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.descriptor_props.CompositeProperty.get_history" title="Permalink to this definition">¶</a></dt>
 
190
<dd><p>Provided for userland code that uses attributes.get_history().</p>
 
191
</dd></dl>
 
192
 
 
193
</dd></dl>
 
194
 
 
195
<dl class="class">
 
196
<dt id="sqlalchemy.orm.state.InstanceState">
 
197
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.state.</tt><tt class="descname">InstanceState</tt><big>(</big><em>obj</em>, <em>manager</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState" title="Permalink to this definition">¶</a></dt>
 
198
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p>
 
199
<p>tracks state information at the instance level.</p>
 
200
<dl class="method">
 
201
<dt id="sqlalchemy.orm.state.InstanceState.commit">
 
202
<tt class="descname">commit</tt><big>(</big><em>dict_</em>, <em>keys</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.commit" title="Permalink to this definition">¶</a></dt>
 
203
<dd><p>Commit attributes.</p>
 
204
<p>This is used by a partial-attribute load operation to mark committed
 
205
those attributes which were refreshed from the database.</p>
 
206
<p>Attributes marked as &#8220;expired&#8221; can potentially remain &#8220;expired&#8221; after
 
207
this step if a value was not populated in state.dict.</p>
 
208
</dd></dl>
 
209
 
 
210
<dl class="method">
 
211
<dt id="sqlalchemy.orm.state.InstanceState.commit_all">
 
212
<tt class="descname">commit_all</tt><big>(</big><em>dict_</em>, <em>instance_dict=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.commit_all" title="Permalink to this definition">¶</a></dt>
 
213
<dd><p>commit all attributes unconditionally.</p>
 
214
<p>This is used after a flush() or a full load/refresh
 
215
to remove all pending state from the instance.</p>
 
216
<blockquote>
 
217
<div><ul class="simple">
 
218
<li>all attributes are marked as &#8220;committed&#8221;</li>
 
219
<li>the &#8220;strong dirty reference&#8221; is removed</li>
 
220
<li>the &#8220;modified&#8221; flag is set to False</li>
 
221
<li>any &#8220;expired&#8221; markers/callables for attributes loaded are removed.</li>
 
222
</ul>
 
223
</div></blockquote>
 
224
<p>Attributes marked as &#8220;expired&#8221; can potentially remain &#8220;expired&#8221; after this step
 
225
if a value was not populated in state.dict.</p>
 
226
</dd></dl>
 
227
 
 
228
<dl class="method">
 
229
<dt id="sqlalchemy.orm.state.InstanceState.expire_attribute_pre_commit">
 
230
<tt class="descname">expire_attribute_pre_commit</tt><big>(</big><em>dict_</em>, <em>key</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.expire_attribute_pre_commit" title="Permalink to this definition">¶</a></dt>
 
231
<dd><p>a fast expire that can be called by column loaders during a load.</p>
 
232
<p>The additional bookkeeping is finished up in commit_all().</p>
 
233
<p>This method is actually called a lot with joined-table
 
234
loading, when the second table isn&#8217;t present in the result.</p>
 
235
</dd></dl>
 
236
 
 
237
<dl class="attribute">
 
238
<dt id="sqlalchemy.orm.state.InstanceState.expired_attributes">
 
239
<tt class="descname">expired_attributes</tt><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.expired_attributes" title="Permalink to this definition">¶</a></dt>
 
240
<dd><p>Return the set of keys which are &#8216;expired&#8217; to be loaded by
 
241
the manager&#8217;s deferred scalar loader, assuming no pending 
 
242
changes.</p>
 
243
<p>see also the <tt class="docutils literal"><span class="pre">unmodified</span></tt> collection which is intersected
 
244
against this set when a refresh operation occurs.</p>
 
245
</dd></dl>
 
246
 
 
247
<dl class="method">
 
248
<dt id="sqlalchemy.orm.state.InstanceState.initialize">
 
249
<tt class="descname">initialize</tt><big>(</big><em>key</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.initialize" title="Permalink to this definition">¶</a></dt>
 
250
<dd><p>Set this attribute to an empty value or collection, 
 
251
based on the AttributeImpl in use.</p>
 
252
</dd></dl>
 
253
 
 
254
<dl class="method">
 
255
<dt id="sqlalchemy.orm.state.InstanceState.reset">
 
256
<tt class="descname">reset</tt><big>(</big><em>dict_</em>, <em>key</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.reset" title="Permalink to this definition">¶</a></dt>
 
257
<dd><p>Remove the given attribute and any 
 
258
callables associated with it.</p>
 
259
</dd></dl>
 
260
 
 
261
<dl class="method">
 
262
<dt id="sqlalchemy.orm.state.InstanceState.set_callable">
 
263
<tt class="descname">set_callable</tt><big>(</big><em>dict_</em>, <em>key</em>, <em>callable_</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.set_callable" title="Permalink to this definition">¶</a></dt>
 
264
<dd><p>Remove the given attribute and set the given callable
 
265
as a loader.</p>
 
266
</dd></dl>
 
267
 
 
268
<dl class="attribute">
 
269
<dt id="sqlalchemy.orm.state.InstanceState.unloaded">
 
270
<tt class="descname">unloaded</tt><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.unloaded" title="Permalink to this definition">¶</a></dt>
 
271
<dd><p>Return the set of keys which do not have a loaded value.</p>
 
272
<p>This includes expired attributes and any other attribute that
 
273
was never populated or modified.</p>
 
274
</dd></dl>
 
275
 
 
276
<dl class="attribute">
 
277
<dt id="sqlalchemy.orm.state.InstanceState.unmodified">
 
278
<tt class="descname">unmodified</tt><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.unmodified" title="Permalink to this definition">¶</a></dt>
 
279
<dd><p>Return the set of keys which have no uncommitted changes</p>
 
280
</dd></dl>
 
281
 
 
282
<dl class="method">
 
283
<dt id="sqlalchemy.orm.state.InstanceState.unmodified_intersection">
 
284
<tt class="descname">unmodified_intersection</tt><big>(</big><em>keys</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.unmodified_intersection" title="Permalink to this definition">¶</a></dt>
 
285
<dd><p>Return self.unmodified.intersection(keys).</p>
 
286
</dd></dl>
 
287
 
 
288
<dl class="method">
 
289
<dt id="sqlalchemy.orm.state.InstanceState.value_as_iterable">
 
290
<tt class="descname">value_as_iterable</tt><big>(</big><em>dict_</em>, <em>key</em>, <em>passive=&lt;symbol 'PASSIVE_OFF&gt;</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.state.InstanceState.value_as_iterable" title="Permalink to this definition">¶</a></dt>
 
291
<dd><p>Return a list of tuples (state, obj) for the given
 
292
key.</p>
 
293
<p>returns an empty list if the value is None/empty/PASSIVE_NO_RESULT</p>
 
294
</dd></dl>
 
295
 
 
296
</dd></dl>
 
297
 
 
298
<dl class="class">
 
299
<dt id="sqlalchemy.orm.interfaces.MapperProperty">
 
300
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.interfaces.</tt><tt class="descname">MapperProperty</tt><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty" title="Permalink to this definition">¶</a></dt>
 
301
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p>
 
302
<p>Manage the relationship of a <tt class="docutils literal"><span class="pre">Mapper</span></tt> to a single class
 
303
attribute, as well as that attribute as it appears on individual
 
304
instances of the class, including attribute instrumentation,
 
305
attribute access, loading behavior, and dependency calculations.</p>
 
306
<dl class="attribute">
 
307
<dt id="sqlalchemy.orm.interfaces.MapperProperty.cascade">
 
308
<tt class="descname">cascade</tt><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.cascade" title="Permalink to this definition">¶</a></dt>
 
309
<dd><p>The set of &#8216;cascade&#8217; attribute names.</p>
 
310
<p>This collection is checked before the &#8216;cascade_iterator&#8217; method is called.</p>
 
311
</dd></dl>
 
312
 
 
313
<dl class="method">
 
314
<dt id="sqlalchemy.orm.interfaces.MapperProperty.cascade_iterator">
 
315
<tt class="descname">cascade_iterator</tt><big>(</big><em>type_</em>, <em>state</em>, <em>visited_instances=None</em>, <em>halt_on=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.cascade_iterator" title="Permalink to this definition">¶</a></dt>
 
316
<dd><p>Iterate through instances related to the given instance for
 
317
a particular &#8216;cascade&#8217;, starting with this MapperProperty.</p>
 
318
<p>Return an iterator3-tuples (instance, mapper, state).</p>
 
319
<p>Note that the &#8216;cascade&#8217; collection on this MapperProperty is
 
320
checked first for the given type before cascade_iterator is called.</p>
 
321
<p>See PropertyLoader for the related instance implementation.</p>
 
322
</dd></dl>
 
323
 
 
324
<dl class="attribute">
 
325
<dt id="sqlalchemy.orm.interfaces.MapperProperty.class_attribute">
 
326
<tt class="descname">class_attribute</tt><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.class_attribute" title="Permalink to this definition">¶</a></dt>
 
327
<dd><p>Return the class-bound descriptor corresponding to this
 
328
MapperProperty.</p>
 
329
</dd></dl>
 
330
 
 
331
<dl class="method">
 
332
<dt id="sqlalchemy.orm.interfaces.MapperProperty.compare">
 
333
<tt class="descname">compare</tt><big>(</big><em>operator</em>, <em>value</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.compare" title="Permalink to this definition">¶</a></dt>
 
334
<dd><p>Return a compare operation for the columns represented by
 
335
this <tt class="docutils literal"><span class="pre">MapperProperty</span></tt> to the given value, which may be a
 
336
column value or an instance.  &#8216;operator&#8217; is an operator from
 
337
the operators module, or from sql.Comparator.</p>
 
338
<p>By default uses the PropComparator attached to this MapperProperty
 
339
under the attribute name &#8220;comparator&#8221;.</p>
 
340
</dd></dl>
 
341
 
 
342
<dl class="method">
 
343
<dt id="sqlalchemy.orm.interfaces.MapperProperty.create_row_processor">
 
344
<tt class="descname">create_row_processor</tt><big>(</big><em>context</em>, <em>path</em>, <em>reduced_path</em>, <em>mapper</em>, <em>row</em>, <em>adapter</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.create_row_processor" title="Permalink to this definition">¶</a></dt>
 
345
<dd><p>Return a 3-tuple consisting of three row processing functions.</p>
 
346
</dd></dl>
 
347
 
 
348
<dl class="method">
 
349
<dt id="sqlalchemy.orm.interfaces.MapperProperty.do_init">
 
350
<tt class="descname">do_init</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.do_init" title="Permalink to this definition">¶</a></dt>
 
351
<dd><p>Perform subclass-specific initialization post-mapper-creation
 
352
steps.</p>
 
353
<p>This is a template method called by the <tt class="docutils literal"><span class="pre">MapperProperty</span></tt>
 
354
object&#8217;s init() method.</p>
 
355
</dd></dl>
 
356
 
 
357
<dl class="method">
 
358
<dt id="sqlalchemy.orm.interfaces.MapperProperty.init">
 
359
<tt class="descname">init</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.init" title="Permalink to this definition">¶</a></dt>
 
360
<dd><p>Called after all mappers are created to assemble
 
361
relationships between mappers and perform other post-mapper-creation
 
362
initialization steps.</p>
 
363
</dd></dl>
 
364
 
 
365
<dl class="method">
 
366
<dt id="sqlalchemy.orm.interfaces.MapperProperty.is_primary">
 
367
<tt class="descname">is_primary</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.is_primary" title="Permalink to this definition">¶</a></dt>
 
368
<dd><p>Return True if this <tt class="docutils literal"><span class="pre">MapperProperty</span></tt>&#8216;s mapper is the
 
369
primary mapper for its class.</p>
 
370
<p>This flag is used to indicate that the <tt class="docutils literal"><span class="pre">MapperProperty</span></tt> can
 
371
define attribute instrumentation for the class at the class
 
372
level (as opposed to the individual instance level).</p>
 
373
</dd></dl>
 
374
 
 
375
<dl class="method">
 
376
<dt id="sqlalchemy.orm.interfaces.MapperProperty.merge">
 
377
<tt class="descname">merge</tt><big>(</big><em>session</em>, <em>source_state</em>, <em>source_dict</em>, <em>dest_state</em>, <em>dest_dict</em>, <em>load</em>, <em>_recursive</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.merge" title="Permalink to this definition">¶</a></dt>
 
378
<dd><p>Merge the attribute represented by this <tt class="docutils literal"><span class="pre">MapperProperty</span></tt>
 
379
from source to destination object</p>
 
380
</dd></dl>
 
381
 
 
382
<dl class="method">
 
383
<dt id="sqlalchemy.orm.interfaces.MapperProperty.post_instrument_class">
 
384
<tt class="descname">post_instrument_class</tt><big>(</big><em>mapper</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.post_instrument_class" title="Permalink to this definition">¶</a></dt>
 
385
<dd><p>Perform instrumentation adjustments that need to occur
 
386
after init() has completed.</p>
 
387
</dd></dl>
 
388
 
 
389
<dl class="method">
 
390
<dt id="sqlalchemy.orm.interfaces.MapperProperty.setup">
 
391
<tt class="descname">setup</tt><big>(</big><em>context</em>, <em>entity</em>, <em>path</em>, <em>reduced_path</em>, <em>adapter</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.MapperProperty.setup" title="Permalink to this definition">¶</a></dt>
 
392
<dd><p>Called by Query for the purposes of constructing a SQL statement.</p>
 
393
<p>Each MapperProperty associated with the target mapper processes the
 
394
statement referenced by the query context, adding columns and/or
 
395
criterion as appropriate.</p>
 
396
</dd></dl>
 
397
 
 
398
</dd></dl>
 
399
 
 
400
<dl class="class">
 
401
<dt id="sqlalchemy.orm.interfaces.PropComparator">
 
402
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.interfaces.</tt><tt class="descname">PropComparator</tt><big>(</big><em>prop</em>, <em>mapper</em>, <em>adapter=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.PropComparator" title="Permalink to this definition">¶</a></dt>
 
403
<dd><p>Bases: <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.operators.ColumnOperators</span></tt></a></p>
 
404
<p>Defines comparison operations for MapperProperty objects.</p>
 
405
<p>User-defined subclasses of <a class="reference internal" href="#sqlalchemy.orm.interfaces.PropComparator" title="sqlalchemy.orm.interfaces.PropComparator"><tt class="xref py py-class docutils literal"><span class="pre">PropComparator</span></tt></a> may be created. The
 
406
built-in Python comparison and math operator methods, such as
 
407
<tt class="docutils literal"><span class="pre">__eq__()</span></tt>, <tt class="docutils literal"><span class="pre">__lt__()</span></tt>, <tt class="docutils literal"><span class="pre">__add__()</span></tt>, can be overridden to provide
 
408
new operator behavior. The custom <a class="reference internal" href="#sqlalchemy.orm.interfaces.PropComparator" title="sqlalchemy.orm.interfaces.PropComparator"><tt class="xref py py-class docutils literal"><span class="pre">PropComparator</span></tt></a> is passed to
 
409
the mapper property via the <tt class="docutils literal"><span class="pre">comparator_factory</span></tt> argument. In each case,
 
410
the appropriate subclass of <a class="reference internal" href="#sqlalchemy.orm.interfaces.PropComparator" title="sqlalchemy.orm.interfaces.PropComparator"><tt class="xref py py-class docutils literal"><span class="pre">PropComparator</span></tt></a> should be used:</p>
 
411
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.orm.properties</span> <span class="kn">import</span> \
 
412
                        <span class="n">ColumnProperty</span><span class="p">,</span>\
 
413
                        <span class="n">CompositeProperty</span><span class="p">,</span>\
 
414
                        <span class="n">RelationshipProperty</span>
 
415
 
 
416
<span class="k">class</span> <span class="nc">MyColumnComparator</span><span class="p">(</span><span class="n">ColumnProperty</span><span class="o">.</span><span class="n">Comparator</span><span class="p">):</span>
 
417
    <span class="k">pass</span>
 
418
 
 
419
<span class="k">class</span> <span class="nc">MyCompositeComparator</span><span class="p">(</span><span class="n">CompositeProperty</span><span class="o">.</span><span class="n">Comparator</span><span class="p">):</span>
 
420
    <span class="k">pass</span>
 
421
 
 
422
<span class="k">class</span> <span class="nc">MyRelationshipComparator</span><span class="p">(</span><span class="n">RelationshipProperty</span><span class="o">.</span><span class="n">Comparator</span><span class="p">):</span>
 
423
    <span class="k">pass</span></pre></div>
 
424
</div>
 
425
<dl class="method">
 
426
<dt id="sqlalchemy.orm.interfaces.PropComparator.adapted">
 
427
<tt class="descname">adapted</tt><big>(</big><em>adapter</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.PropComparator.adapted" title="Permalink to this definition">¶</a></dt>
 
428
<dd><p>Return a copy of this PropComparator which will use the given
 
429
adaption function on the local side of generated expressions.</p>
 
430
</dd></dl>
 
431
 
 
432
<dl class="method">
 
433
<dt id="sqlalchemy.orm.interfaces.PropComparator.any">
 
434
<tt class="descname">any</tt><big>(</big><em>criterion=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.PropComparator.any" title="Permalink to this definition">¶</a></dt>
 
435
<dd><p>Return true if this collection contains any member that meets the
 
436
given criterion.</p>
 
437
<dl class="docutils">
 
438
<dt>criterion</dt>
 
439
<dd>an optional ClauseElement formulated against the member class&#8217; table
 
440
or attributes.</dd>
 
441
<dt>**kwargs</dt>
 
442
<dd>key/value pairs corresponding to member class attribute names which
 
443
will be compared via equality to the corresponding values.</dd>
 
444
</dl>
 
445
</dd></dl>
 
446
 
 
447
<dl class="method">
 
448
<dt id="sqlalchemy.orm.interfaces.PropComparator.has">
 
449
<tt class="descname">has</tt><big>(</big><em>criterion=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.PropComparator.has" title="Permalink to this definition">¶</a></dt>
 
450
<dd><p>Return true if this element references a member which meets the
 
451
given criterion.</p>
 
452
<dl class="docutils">
 
453
<dt>criterion</dt>
 
454
<dd>an optional ClauseElement formulated against the member class&#8217; table
 
455
or attributes.</dd>
 
456
<dt>**kwargs</dt>
 
457
<dd>key/value pairs corresponding to member class attribute names which
 
458
will be compared via equality to the corresponding values.</dd>
 
459
</dl>
 
460
</dd></dl>
 
461
 
 
462
<dl class="method">
 
463
<dt id="sqlalchemy.orm.interfaces.PropComparator.of_type">
 
464
<tt class="descname">of_type</tt><big>(</big><em>class_</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.PropComparator.of_type" title="Permalink to this definition">¶</a></dt>
 
465
<dd><p>Redefine this object in terms of a polymorphic subclass.</p>
 
466
<p>Returns a new PropComparator from which further criterion can be
 
467
evaluated.</p>
 
468
<p>e.g.:</p>
 
469
<div class="highlight-python"><div class="highlight"><pre><span class="n">query</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">Company</span><span class="o">.</span><span class="n">employees</span><span class="o">.</span><span class="n">of_type</span><span class="p">(</span><span class="n">Engineer</span><span class="p">))</span><span class="o">.</span>\
 
470
   <span class="nb">filter</span><span class="p">(</span><span class="n">Engineer</span><span class="o">.</span><span class="n">name</span><span class="o">==</span><span class="s">&#39;foo&#39;</span><span class="p">)</span></pre></div>
 
471
</div>
 
472
<dl class="docutils">
 
473
<dt>class_</dt>
 
474
<dd>a class or mapper indicating that criterion will be against
 
475
this specific subclass.</dd>
 
476
</dl>
 
477
</dd></dl>
 
478
 
 
479
</dd></dl>
 
480
 
 
481
<dl class="class">
 
482
<dt id="sqlalchemy.orm.properties.RelationshipProperty">
 
483
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.properties.</tt><tt class="descname">RelationshipProperty</tt><big>(</big><em>argument</em>, <em>secondary=None</em>, <em>primaryjoin=None</em>, <em>secondaryjoin=None</em>, <em>foreign_keys=None</em>, <em>uselist=None</em>, <em>order_by=False</em>, <em>backref=None</em>, <em>back_populates=None</em>, <em>post_update=False</em>, <em>cascade=False</em>, <em>extension=None</em>, <em>viewonly=False</em>, <em>lazy=True</em>, <em>collection_class=None</em>, <em>passive_deletes=False</em>, <em>passive_updates=True</em>, <em>remote_side=None</em>, <em>enable_typechecks=True</em>, <em>join_depth=None</em>, <em>comparator_factory=None</em>, <em>single_parent=False</em>, <em>innerjoin=False</em>, <em>doc=None</em>, <em>active_history=False</em>, <em>cascade_backrefs=True</em>, <em>load_on_pending=False</em>, <em>strategy_class=None</em>, <em>_local_remote_pairs=None</em>, <em>query_class=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty" title="Permalink to this definition">¶</a></dt>
 
484
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.orm.interfaces.StrategizedProperty</span></tt></p>
 
485
<p>Describes an object property that holds a single item or list
 
486
of items that correspond to a related database table.</p>
 
487
<p>Public constructor is the <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">orm.relationship()</span></tt></a> function.</p>
 
488
<p>Of note here is the <a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator"><tt class="xref py py-class docutils literal"><span class="pre">RelationshipProperty.Comparator</span></tt></a>
 
489
class, which implements comparison operations for scalar-
 
490
and collection-referencing mapped attributes.</p>
 
491
<dl class="class">
 
492
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator">
 
493
<em class="property">class </em><tt class="descname">Comparator</tt><big>(</big><em>prop</em>, <em>mapper</em>, <em>of_type=None</em>, <em>adapter=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator" title="Permalink to this definition">¶</a></dt>
 
494
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.orm.interfaces.PropComparator" title="sqlalchemy.orm.interfaces.PropComparator"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.orm.interfaces.PropComparator</span></tt></a></p>
 
495
<p>Produce comparison operations for <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a>-based
 
496
attributes.</p>
 
497
<dl class="method">
 
498
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator.__eq__">
 
499
<tt class="descname">__eq__</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.__eq__" title="Permalink to this definition">¶</a></dt>
 
500
<dd><p>Implement the <tt class="docutils literal"><span class="pre">==</span></tt> operator.</p>
 
501
<p>In a many-to-one context, such as:</p>
 
502
<div class="highlight-python"><pre>MyClass.some_prop == &lt;some object&gt;</pre>
 
503
</div>
 
504
<p>this will typically produce a
 
505
clause such as:</p>
 
506
<div class="highlight-python"><pre>mytable.related_id == &lt;some id&gt;</pre>
 
507
</div>
 
508
<p>Where <tt class="docutils literal"><span class="pre">&lt;some</span> <span class="pre">id&gt;</span></tt> is the primary key of the given 
 
509
object.</p>
 
510
<p>The <tt class="docutils literal"><span class="pre">==</span></tt> operator provides partial functionality for non-
 
511
many-to-one comparisons:</p>
 
512
<ul class="simple">
 
513
<li>Comparisons against collections are not supported.
 
514
Use <a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains"><tt class="xref py py-meth docutils literal"><span class="pre">contains()</span></tt></a>.</li>
 
515
<li>Compared to a scalar one-to-many, will produce a 
 
516
clause that compares the target columns in the parent to
 
517
the given target.</li>
 
518
<li>Compared to a scalar many-to-many, an alias
 
519
of the association table will be rendered as
 
520
well, forming a natural join that is part of the
 
521
main body of the query. This will not work for
 
522
queries that go beyond simple AND conjunctions of
 
523
comparisons, such as those which use OR. Use
 
524
explicit joins, outerjoins, or
 
525
<a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.has" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.has"><tt class="xref py py-meth docutils literal"><span class="pre">has()</span></tt></a> for
 
526
more comprehensive non-many-to-one scalar
 
527
membership tests.</li>
 
528
<li>Comparisons against <tt class="xref docutils literal"><span class="pre">None</span></tt> given in a one-to-many
 
529
or many-to-many context produce a NOT EXISTS clause.</li>
 
530
</ul>
 
531
</dd></dl>
 
532
 
 
533
<dl class="method">
 
534
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator.__init__">
 
535
<tt class="descname">__init__</tt><big>(</big><em>prop</em>, <em>mapper</em>, <em>of_type=None</em>, <em>adapter=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.__init__" title="Permalink to this definition">¶</a></dt>
 
536
<dd><p>Construction of <a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator"><tt class="xref py py-class docutils literal"><span class="pre">RelationshipProperty.Comparator</span></tt></a>
 
537
is internal to the ORM&#8217;s attribute mechanics.</p>
 
538
</dd></dl>
 
539
 
 
540
<dl class="method">
 
541
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator.__ne__">
 
542
<tt class="descname">__ne__</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.__ne__" title="Permalink to this definition">¶</a></dt>
 
543
<dd><p>Implement the <tt class="docutils literal"><span class="pre">!=</span></tt> operator.</p>
 
544
<p>In a many-to-one context, such as:</p>
 
545
<div class="highlight-python"><pre>MyClass.some_prop != &lt;some object&gt;</pre>
 
546
</div>
 
547
<p>This will typically produce a clause such as:</p>
 
548
<div class="highlight-python"><pre>mytable.related_id != &lt;some id&gt;</pre>
 
549
</div>
 
550
<p>Where <tt class="docutils literal"><span class="pre">&lt;some</span> <span class="pre">id&gt;</span></tt> is the primary key of the
 
551
given object.</p>
 
552
<p>The <tt class="docutils literal"><span class="pre">!=</span></tt> operator provides partial functionality for non-
 
553
many-to-one comparisons:</p>
 
554
<ul class="simple">
 
555
<li>Comparisons against collections are not supported.
 
556
Use
 
557
<a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains"><tt class="xref py py-meth docutils literal"><span class="pre">contains()</span></tt></a>
 
558
in conjunction with <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.not_" title="sqlalchemy.sql.expression.not_"><tt class="xref py py-func docutils literal"><span class="pre">not_()</span></tt></a>.</li>
 
559
<li>Compared to a scalar one-to-many, will produce a 
 
560
clause that compares the target columns in the parent to
 
561
the given target.</li>
 
562
<li>Compared to a scalar many-to-many, an alias
 
563
of the association table will be rendered as
 
564
well, forming a natural join that is part of the
 
565
main body of the query. This will not work for
 
566
queries that go beyond simple AND conjunctions of
 
567
comparisons, such as those which use OR. Use
 
568
explicit joins, outerjoins, or
 
569
<a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.has" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.has"><tt class="xref py py-meth docutils literal"><span class="pre">has()</span></tt></a> in
 
570
conjunction with <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.not_" title="sqlalchemy.sql.expression.not_"><tt class="xref py py-func docutils literal"><span class="pre">not_()</span></tt></a> for
 
571
more comprehensive non-many-to-one scalar
 
572
membership tests.</li>
 
573
<li>Comparisons against <tt class="xref docutils literal"><span class="pre">None</span></tt> given in a one-to-many
 
574
or many-to-many context produce an EXISTS clause.</li>
 
575
</ul>
 
576
</dd></dl>
 
577
 
 
578
<dl class="method">
 
579
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator.adapted">
 
580
<tt class="descname">adapted</tt><big>(</big><em>adapter</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.adapted" title="Permalink to this definition">¶</a></dt>
 
581
<dd><p>Return a copy of this PropComparator which will use the
 
582
given adaption function on the local side of generated
 
583
expressions.</p>
 
584
</dd></dl>
 
585
 
 
586
<dl class="method">
 
587
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator.any">
 
588
<tt class="descname">any</tt><big>(</big><em>criterion=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.any" title="Permalink to this definition">¶</a></dt>
 
589
<dd><p>Produce an expression that tests a collection against
 
590
particular criterion, using EXISTS.</p>
 
591
<p>An expression like:</p>
 
592
<div class="highlight-python"><div class="highlight"><pre><span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">MyClass</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
 
593
    <span class="n">MyClass</span><span class="o">.</span><span class="n">somereference</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">SomeRelated</span><span class="o">.</span><span class="n">x</span><span class="o">==</span><span class="mi">2</span><span class="p">)</span>
 
594
<span class="p">)</span></pre></div>
 
595
</div>
 
596
<p>Will produce a query like:</p>
 
597
<div class="highlight-python"><pre>SELECT * FROM my_table WHERE
 
598
EXISTS (SELECT 1 FROM related WHERE related.my_id=my_table.id 
 
599
AND related.x=2)</pre>
 
600
</div>
 
601
<p>Because <a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.any" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.any"><tt class="xref py py-meth docutils literal"><span class="pre">any()</span></tt></a> uses
 
602
a correlated subquery, its performance is not nearly as
 
603
good when compared against large target tables as that of
 
604
using a join.</p>
 
605
<p><a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.any" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.any"><tt class="xref py py-meth docutils literal"><span class="pre">any()</span></tt></a> is particularly
 
606
useful for testing for empty collections:</p>
 
607
<div class="highlight-python"><div class="highlight"><pre><span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">MyClass</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
 
608
    <span class="o">~</span><span class="n">MyClass</span><span class="o">.</span><span class="n">somereference</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
 
609
<span class="p">)</span></pre></div>
 
610
</div>
 
611
<p>will produce:</p>
 
612
<div class="highlight-python"><pre>SELECT * FROM my_table WHERE
 
613
NOT EXISTS (SELECT 1 FROM related WHERE related.my_id=my_table.id)</pre>
 
614
</div>
 
615
<p><a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.any" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.any"><tt class="xref py py-meth docutils literal"><span class="pre">any()</span></tt></a> is only
 
616
valid for collections, i.e. a <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a>
 
617
that has <tt class="docutils literal"><span class="pre">uselist=True</span></tt>.  For scalar references,
 
618
use <a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.has" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.has"><tt class="xref py py-meth docutils literal"><span class="pre">has()</span></tt></a>.</p>
 
619
</dd></dl>
 
620
 
 
621
<dl class="method">
 
622
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains">
 
623
<tt class="descname">contains</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains" title="Permalink to this definition">¶</a></dt>
 
624
<dd><p>Return a simple expression that tests a collection for 
 
625
containment of a particular item.</p>
 
626
<p><a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains"><tt class="xref py py-meth docutils literal"><span class="pre">contains()</span></tt></a> is
 
627
only valid for a collection, i.e. a
 
628
<a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> that implements
 
629
one-to-many or many-to-many with <tt class="docutils literal"><span class="pre">uselist=True</span></tt>.</p>
 
630
<p>When used in a simple one-to-many context, an 
 
631
expression like:</p>
 
632
<div class="highlight-python"><div class="highlight"><pre><span class="n">MyClass</span><span class="o">.</span><span class="n">contains</span><span class="p">(</span><span class="n">other</span><span class="p">)</span></pre></div>
 
633
</div>
 
634
<p>Produces a clause like:</p>
 
635
<div class="highlight-python"><pre>mytable.id == &lt;some id&gt;</pre>
 
636
</div>
 
637
<p>Where <tt class="docutils literal"><span class="pre">&lt;some</span> <span class="pre">id&gt;</span></tt> is the value of the foreign key
 
638
attribute on <tt class="docutils literal"><span class="pre">other</span></tt> which refers to the primary
 
639
key of its parent object. From this it follows that
 
640
<a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains"><tt class="xref py py-meth docutils literal"><span class="pre">contains()</span></tt></a> is
 
641
very useful when used with simple one-to-many
 
642
operations.</p>
 
643
<p>For many-to-many operations, the behavior of
 
644
<a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains"><tt class="xref py py-meth docutils literal"><span class="pre">contains()</span></tt></a>
 
645
has more caveats. The association table will be
 
646
rendered in the statement, producing an &#8220;implicit&#8221;
 
647
join, that is, includes multiple tables in the FROM
 
648
clause which are equated in the WHERE clause:</p>
 
649
<div class="highlight-python"><div class="highlight"><pre><span class="n">query</span><span class="p">(</span><span class="n">MyClass</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">MyClass</span><span class="o">.</span><span class="n">contains</span><span class="p">(</span><span class="n">other</span><span class="p">))</span></pre></div>
 
650
</div>
 
651
<p>Produces a query like:</p>
 
652
<div class="highlight-python"><pre>SELECT * FROM my_table, my_association_table AS
 
653
my_association_table_1 WHERE
 
654
my_table.id = my_association_table_1.parent_id
 
655
AND my_association_table_1.child_id = &lt;some id&gt;</pre>
 
656
</div>
 
657
<p>Where <tt class="docutils literal"><span class="pre">&lt;some</span> <span class="pre">id&gt;</span></tt> would be the primary key of
 
658
<tt class="docutils literal"><span class="pre">other</span></tt>. From the above, it is clear that
 
659
<a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains"><tt class="xref py py-meth docutils literal"><span class="pre">contains()</span></tt></a>
 
660
will <strong>not</strong> work with many-to-many collections when
 
661
used in queries that move beyond simple AND
 
662
conjunctions, such as multiple
 
663
<a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains"><tt class="xref py py-meth docutils literal"><span class="pre">contains()</span></tt></a>
 
664
expressions joined by OR. In such cases subqueries or
 
665
explicit &#8220;outer joins&#8221; will need to be used instead.
 
666
See <a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.any" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.any"><tt class="xref py py-meth docutils literal"><span class="pre">any()</span></tt></a> for
 
667
a less-performant alternative using EXISTS, or refer
 
668
to <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query.outerjoin" title="sqlalchemy.orm.query.Query.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">Query.outerjoin()</span></tt></a> as well as <a class="reference internal" href="tutorial.html#ormtutorial-joins"><em>Querying with Joins</em></a>
 
669
for more details on constructing outer joins.</p>
 
670
</dd></dl>
 
671
 
 
672
<dl class="method">
 
673
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator.has">
 
674
<tt class="descname">has</tt><big>(</big><em>criterion=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.has" title="Permalink to this definition">¶</a></dt>
 
675
<dd><p>Produce an expression that tests a scalar reference against
 
676
particular criterion, using EXISTS.</p>
 
677
<p>An expression like:</p>
 
678
<div class="highlight-python"><div class="highlight"><pre><span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">MyClass</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
 
679
    <span class="n">MyClass</span><span class="o">.</span><span class="n">somereference</span><span class="o">.</span><span class="n">has</span><span class="p">(</span><span class="n">SomeRelated</span><span class="o">.</span><span class="n">x</span><span class="o">==</span><span class="mi">2</span><span class="p">)</span>
 
680
<span class="p">)</span></pre></div>
 
681
</div>
 
682
<p>Will produce a query like:</p>
 
683
<div class="highlight-python"><pre>SELECT * FROM my_table WHERE
 
684
EXISTS (SELECT 1 FROM related WHERE related.id==my_table.related_id
 
685
AND related.x=2)</pre>
 
686
</div>
 
687
<p>Because <a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.has" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.has"><tt class="xref py py-meth docutils literal"><span class="pre">has()</span></tt></a> uses
 
688
a correlated subquery, its performance is not nearly as
 
689
good when compared against large target tables as that of
 
690
using a join.</p>
 
691
<p><a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.has" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.has"><tt class="xref py py-meth docutils literal"><span class="pre">has()</span></tt></a> is only
 
692
valid for scalar references, i.e. a <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a>
 
693
that has <tt class="docutils literal"><span class="pre">uselist=False</span></tt>.  For collection references,
 
694
use <a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.any" title="sqlalchemy.orm.properties.RelationshipProperty.Comparator.any"><tt class="xref py py-meth docutils literal"><span class="pre">any()</span></tt></a>.</p>
 
695
</dd></dl>
 
696
 
 
697
<dl class="method">
 
698
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator.in_">
 
699
<tt class="descname">in_</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.in_" title="Permalink to this definition">¶</a></dt>
 
700
<dd><p>Produce an IN clause - this is not implemented 
 
701
for <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a>-based attributes at this time.</p>
 
702
</dd></dl>
 
703
 
 
704
<dl class="method">
 
705
<dt id="sqlalchemy.orm.properties.RelationshipProperty.Comparator.of_type">
 
706
<tt class="descname">of_type</tt><big>(</big><em>cls</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.Comparator.of_type" title="Permalink to this definition">¶</a></dt>
 
707
<dd><p>Produce a construct that represents a particular &#8216;subtype&#8217; of
 
708
attribute for the parent class.</p>
 
709
<p>Currently this is usable in conjunction with <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query.join" title="sqlalchemy.orm.query.Query.join"><tt class="xref py py-meth docutils literal"><span class="pre">Query.join()</span></tt></a>
 
710
and <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query.outerjoin" title="sqlalchemy.orm.query.Query.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">Query.outerjoin()</span></tt></a>.</p>
 
711
</dd></dl>
 
712
 
 
713
</dd></dl>
 
714
 
 
715
<dl class="attribute">
 
716
<dt id="sqlalchemy.orm.properties.RelationshipProperty.mapper">
 
717
<tt class="descclassname">RelationshipProperty.</tt><tt class="descname">mapper</tt><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.mapper" title="Permalink to this definition">¶</a></dt>
 
718
<dd><p>Return the targeted <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> for this 
 
719
<a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty" title="sqlalchemy.orm.properties.RelationshipProperty"><tt class="xref py py-class docutils literal"><span class="pre">RelationshipProperty</span></tt></a>.</p>
 
720
<p>This is a lazy-initializing static attribute.</p>
 
721
</dd></dl>
 
722
 
 
723
<dl class="attribute">
 
724
<dt id="sqlalchemy.orm.properties.RelationshipProperty.table">
 
725
<tt class="descclassname">RelationshipProperty.</tt><tt class="descname">table</tt><a class="headerlink" href="#sqlalchemy.orm.properties.RelationshipProperty.table" title="Permalink to this definition">¶</a></dt>
 
726
<dd><p>Return the selectable linked to this</p>
 
727
<p class="deprecated">
 
728
<span class="versionmodified">Deprecated since version 0.7: </span>Use .target</p>
 
729
<p><a class="reference internal" href="#sqlalchemy.orm.properties.RelationshipProperty" title="sqlalchemy.orm.properties.RelationshipProperty"><tt class="xref py py-class docutils literal"><span class="pre">RelationshipProperty</span></tt></a> object&#8217;s target 
 
730
<a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a>.</p>
 
731
</dd></dl>
 
732
 
 
733
</dd></dl>
 
734
 
 
735
<dl class="class">
 
736
<dt id="sqlalchemy.orm.descriptor_props.SynonymProperty">
 
737
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.descriptor_props.</tt><tt class="descname">SynonymProperty</tt><big>(</big><em>name</em>, <em>map_column=None</em>, <em>descriptor=None</em>, <em>comparator_factory=None</em>, <em>doc=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.descriptor_props.SynonymProperty" title="Permalink to this definition">¶</a></dt>
 
738
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.orm.descriptor_props.DescriptorProperty</span></tt></p>
 
739
</dd></dl>
 
740
 
 
741
<dl class="class">
 
742
<dt id="sqlalchemy.orm.query.QueryContext">
 
743
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.query.</tt><tt class="descname">QueryContext</tt><big>(</big><em>query</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.query.QueryContext" title="Permalink to this definition">¶</a></dt>
 
744
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p>
 
745
</dd></dl>
 
746
 
 
747
</div>
 
748
 
 
749
    </div>
 
750
</div>
 
751
 
 
752
 
 
753
    <div class="bottomnav">
 
754
            Previous:
 
755
            <a href="exceptions.html" title="previous chapter">ORM Exceptions</a>
 
756
            Next:
 
757
            <a href="../core/index.html" title="next chapter">SQLAlchemy Core</a>
 
758
        <div class="doc_copyright">
 
759
            &copy; <a href="../copyright.html">Copyright</a> 2007-2011, the SQLAlchemy authors and contributors.
 
760
            Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
 
761
        </div>
 
762
    </div>
 
763
 
 
764
 
 
765
 
 
766
 
 
767
    </body>
 
768
</html>
 
769
 
 
770
 
 
771