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

« back to all changes in this revision

Viewing changes to doc/orm/mapper_config.html

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2013-10-28 22:29:40 UTC
  • mfrom: (1.4.24)
  • Revision ID: package-import@ubuntu.com-20131028222940-wvyqffl4g617caun
Tags: 0.8.3-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    <script type="text/javascript">
21
21
      var DOCUMENTATION_OPTIONS = {
22
22
          URL_ROOT:    '../',
23
 
          VERSION:     '0.8.2',
 
23
          VERSION:     '0.8.3',
24
24
          COLLAPSE_MODINDEX: false,
25
25
          FILE_SUFFIX: '.html'
26
26
      };
67
67
    </div>
68
68
 
69
69
    <div id="docs-version-header">
70
 
        Release: <span class="version-num">0.8.2</span> | Release Date: July 3, 2013
 
70
        Release: <span class="version-num">0.8.3</span> | Release Date: October 26, 2013
71
71
 
72
72
 
73
73
    </div>
148
148
<li><a class="reference internal" href="#mapping-a-class-against-arbitrary-selects">Mapping a Class against Arbitrary Selects</a></li>
149
149
<li><a class="reference internal" href="#multiple-mappers-for-one-class">Multiple Mappers for One Class</a></li>
150
150
<li><a class="reference internal" href="#constructors-and-object-initialization">Constructors and Object Initialization</a></li>
 
151
<li><a class="reference internal" href="#configuring-a-version-counter">Configuring a Version Counter</a><ul>
 
152
<li><a class="reference internal" href="#simple-version-counting">Simple Version Counting</a></li>
 
153
<li><a class="reference internal" href="#custom-version-counters-types">Custom Version Counters / Types</a></li>
 
154
</ul>
 
155
</li>
151
156
<li><a class="reference internal" href="#class-mapping-api">Class Mapping API</a></li>
152
157
</ul>
153
158
</li>
195
200
    <span class="n">fullname</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">)</span>
196
201
    <span class="n">password</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">)</span></pre></div>
197
202
</div>
198
 
<p>In &#8220;classical&#8221; form, the table metadata is created separately with the <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
 
203
<p>In &#8220;classical&#8221; form, the table metadata is created separately with the <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
199
204
construct, then associated with the <tt class="docutils literal"><span class="pre">User</span></tt> class via the <a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a> function:</p>
200
205
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">MetaData</span><span class="p">,</span> <span class="n">Column</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">String</span>
201
206
<span class="kn">from</span> <span class="nn">sqlalchemy.orm</span> <span class="kn">import</span> <span class="n">mapper</span>
218
223
<span class="n">mapper</span><span class="p">(</span><span class="n">User</span><span class="p">,</span> <span class="n">user</span><span class="p">)</span></pre></div>
219
224
</div>
220
225
<p>Information about mapped attributes, such as relationships to other classes, are provided
221
 
via the <tt class="docutils literal"><span class="pre">properties</span></tt> dictionary.  The example below illustrates a second <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
 
226
via the <tt class="docutils literal"><span class="pre">properties</span></tt> dictionary.  The example below illustrates a second <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
222
227
object, mapped to a class called <tt class="docutils literal"><span class="pre">Address</span></tt>, then linked to <tt class="docutils literal"><span class="pre">User</span></tt> via <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>:</p>
223
228
<div class="highlight-python"><div class="highlight"><pre><span class="n">address</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&#39;address&#39;</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
224
229
            <span class="n">Column</span><span class="p">(</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
234
239
</div>
235
240
<p>When using classical mappings, classes must be provided directly without the benefit
236
241
of the &#8220;string lookup&#8221; system provided by Declarative.  SQL expressions are typically
237
 
specified in terms of the <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects, i.e. <tt class="docutils literal"><span class="pre">address.c.id</span></tt> above
 
242
specified in terms of the <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects, i.e. <tt class="docutils literal"><span class="pre">address.c.id</span></tt> above
238
243
for the <tt class="docutils literal"><span class="pre">Address</span></tt> relationship, and not <tt class="docutils literal"><span class="pre">Address.id</span></tt>, as <tt class="docutils literal"><span class="pre">Address</span></tt> may not
239
244
yet be linked to table metadata, nor can we specify a string here.</p>
240
245
<p>Some examples in the documentation still use the classical approach, but note that
241
246
the classical as well as Declarative approaches are <strong>fully interchangeable</strong>.  Both
242
 
systems ultimately create the same configuration, consisting of a <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>,
 
247
systems ultimately create the same configuration, consisting of a <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>,
243
248
user-defined class, linked together with a <a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a>.  When we talk about
244
249
&#8220;the behavior of <a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a>&#8221;, this includes when using the Declarative system
245
250
as well - it&#8217;s still used, just behind the scenes.</p>
247
252
<div class="section" id="customizing-column-properties">
248
253
<h2>Customizing Column Properties<a class="headerlink" href="#customizing-column-properties" title="Permalink to this headline">¶</a></h2>
249
254
<p>The default behavior of <a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a> is to assemble all the columns in
250
 
the mapped <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> into mapped object attributes, each of which are
 
255
the mapped <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> into mapped object attributes, each of which are
251
256
named according to the name of the column itself (specifically, the <tt class="docutils literal"><span class="pre">key</span></tt>
252
 
attribute of <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>).  This behavior can be
 
257
attribute of <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>).  This behavior can be
253
258
modified in several ways.</p>
254
259
<div class="section" id="naming-columns-distinctly-from-attribute-names">
255
 
<h3>Naming Columns Distinctly from Attribute Names<a class="headerlink" href="#naming-columns-distinctly-from-attribute-names" title="Permalink to this headline">¶</a></h3>
 
260
<span id="mapper-column-distinct-names"></span><h3>Naming Columns Distinctly from Attribute Names<a class="headerlink" href="#naming-columns-distinctly-from-attribute-names" title="Permalink to this headline">¶</a></h3>
256
261
<p>A mapping by default shares the same name for a
257
 
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> as that of the mapped attribute.
258
 
The name assigned to the <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> can be different,
 
262
<a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> as that of the mapped attribute.
 
263
The name assigned to the <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> can be different,
259
264
as we illustrate here in a Declarative mapping:</p>
260
265
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
261
266
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;user&#39;</span>
264
269
</div>
265
270
<p>Where above <tt class="docutils literal"><span class="pre">User.id</span></tt> resolves to a column named <tt class="docutils literal"><span class="pre">user_id</span></tt>
266
271
and <tt class="docutils literal"><span class="pre">User.name</span></tt> resolves to a column named <tt class="docutils literal"><span class="pre">user_name</span></tt>.</p>
267
 
<p>When mapping to an existing table, the <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object
 
272
<p>When mapping to an existing table, the <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object
268
273
can be referenced directly:</p>
269
274
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
270
275
    <span class="n">__table__</span> <span class="o">=</span> <span class="n">user_table</span>
296
301
</div>
297
302
<div class="section" id="using-column-property-for-column-level-options">
298
303
<h3>Using column_property for column level options<a class="headerlink" href="#using-column-property-for-column-level-options" title="Permalink to this headline">¶</a></h3>
299
 
<p>Options can be specified when mapping a <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> using the
 
304
<p>Options can be specified when mapping a <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> using the
300
305
<a class="reference internal" href="#sqlalchemy.orm.column_property" title="sqlalchemy.orm.column_property"><tt class="xref py py-func docutils literal"><span class="pre">column_property()</span></tt></a> function.  This function
301
306
explicitly creates the <a class="reference internal" href="internals.html#sqlalchemy.orm.properties.ColumnProperty" title="sqlalchemy.orm.properties.ColumnProperty"><tt class="xref py py-class docutils literal"><span class="pre">ColumnProperty</span></tt></a> used by the
302
 
<a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a> to keep track of the <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>; normally, the
 
307
<a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a> to keep track of the <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>; normally, the
303
308
<a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a> creates this automatically.   Using <a class="reference internal" href="#sqlalchemy.orm.column_property" title="sqlalchemy.orm.column_property"><tt class="xref py py-func docutils literal"><span class="pre">column_property()</span></tt></a>,
304
 
we can pass additional arguments about how we&#8217;d like the <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
 
309
we can pass additional arguments about how we&#8217;d like the <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
305
310
to be mapped.   Below, we pass an option <tt class="docutils literal"><span class="pre">active_history</span></tt>,
306
311
which specifies that a change to this column&#8217;s value should
307
312
result in the former value being loaded first:</p>
314
319
    <span class="n">name</span> <span class="o">=</span> <span class="n">column_property</span><span class="p">(</span><span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">)),</span> <span class="n">active_history</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span></pre></div>
315
320
</div>
316
321
<p><a class="reference internal" href="#sqlalchemy.orm.column_property" title="sqlalchemy.orm.column_property"><tt class="xref py py-func docutils literal"><span class="pre">column_property()</span></tt></a> is also used to map a single attribute to
317
 
multiple columns.  This use case arises when mapping to a <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.join" title="sqlalchemy.sql.expression.join"><tt class="xref py py-func docutils literal"><span class="pre">join()</span></tt></a>
 
322
multiple columns.  This use case arises when mapping to a <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.join" title="sqlalchemy.sql.expression.join"><tt class="xref py py-func docutils literal"><span class="pre">join()</span></tt></a>
318
323
which has attributes which are equated to each other:</p>
319
324
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
320
325
    <span class="n">__table__</span> <span class="o">=</span> <span class="n">user</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">address</span><span class="p">)</span>
341
346
<tt class="descclassname">sqlalchemy.orm.</tt><tt class="descname">column_property</tt><big>(</big><em>*cols</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.column_property" title="Permalink to this definition">¶</a></dt>
342
347
<dd><p>Provide a column-level property for use with a Mapper.</p>
343
348
<p>Column-based properties can normally be applied to the mapper&#8217;s
344
 
<tt class="docutils literal"><span class="pre">properties</span></tt> dictionary using the <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> element directly.
 
349
<tt class="docutils literal"><span class="pre">properties</span></tt> dictionary using the <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> element directly.
345
350
Use this function when the given column is not directly present within the
346
351
mapper&#8217;s selectable; examples include SQL expressions, functions, and
347
352
scalar SELECT queries.</p>
362
367
<a class="reference internal" href="session.html#sqlalchemy.orm.attributes.get_history" title="sqlalchemy.orm.attributes.get_history"><tt class="xref py py-func docutils literal"><span class="pre">attributes.get_history()</span></tt></a> or <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.is_modified" title="sqlalchemy.orm.session.Session.is_modified"><tt class="xref py py-meth docutils literal"><span class="pre">Session.is_modified()</span></tt></a>
363
368
which also need to know
364
369
the &#8220;previous&#8221; value of the attribute.</p>
365
 
<p class="versionadded">
366
 
<span class="versionmodified">New in version 0.6.6.</span></p>
 
370
<div class="versionadded">
 
371
<p><span>New in version 0.6.6.</span></p>
 
372
</div>
367
373
</li>
368
374
<li><strong>comparator_factory</strong> &#8211; a class which extends
369
375
<a class="reference internal" href="internals.html#sqlalchemy.orm.properties.ColumnProperty.Comparator" title="sqlalchemy.orm.properties.ColumnProperty.Comparator"><tt class="xref py py-class docutils literal"><span class="pre">ColumnProperty.Comparator</span></tt></a> which provides custom SQL clause
387
393
Note however that the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> with default expiration
388
394
settings still expires
389
395
all attributes after a <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.commit" title="sqlalchemy.orm.session.Session.commit"><tt class="xref py py-meth docutils literal"><span class="pre">Session.commit()</span></tt></a> call, however.</p>
390
 
<p class="versionadded">
391
 
<span class="versionmodified">New in version 0.7.3.</span></p>
 
396
<div class="versionadded">
 
397
<p><span>New in version 0.7.3.</span></p>
 
398
</div>
392
399
</li>
393
400
<li><strong>info</strong> &#8211; <p>Optional data dictionary which will be populated into the
394
401
<a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces.MapperProperty.info" title="sqlalchemy.orm.interfaces.MapperProperty.info"><tt class="xref py py-attr docutils literal"><span class="pre">MapperProperty.info</span></tt></a> attribute of this object.</p>
395
 
<p class="versionadded">
396
 
<span class="versionmodified">New in version 0.8.</span></p>
 
402
<div class="versionadded">
 
403
<p><span>New in version 0.8.</span></p>
 
404
</div>
397
405
</li>
398
406
<li><strong>extension</strong> &#8211; an
399
407
<a class="reference internal" href="deprecated.html#sqlalchemy.orm.interfaces.AttributeExtension" title="sqlalchemy.orm.interfaces.AttributeExtension"><tt class="xref py py-class docutils literal"><span class="pre">AttributeExtension</span></tt></a>
411
419
</div>
412
420
<div class="section" id="mapping-a-subset-of-table-columns">
413
421
<span id="include-exclude-cols"></span><h3>Mapping a Subset of Table Columns<a class="headerlink" href="#mapping-a-subset-of-table-columns" title="Permalink to this headline">¶</a></h3>
414
 
<p>Sometimes, a <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object was made available using the
415
 
reflection process described at <a class="reference internal" href="../core/schema.html#metadata-reflection"><em>Reflecting Database Objects</em></a> to load
 
422
<p>Sometimes, a <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object was made available using the
 
423
reflection process described at <em class="xref std std-ref">metadata_reflection</em> to load
416
424
the table&#8217;s structure from the database.
417
425
For such a table that has lots of columns that don&#8217;t need to be referenced
418
426
in the application, the <tt class="docutils literal"><span class="pre">include_properties</span></tt> or <tt class="docutils literal"><span class="pre">exclude_properties</span></tt>
443
451
<p>In some cases, multiple columns may have the same name, such as when
444
452
mapping to a join of two or more tables that share some column name.
445
453
<tt class="docutils literal"><span class="pre">include_properties</span></tt> and <tt class="docutils literal"><span class="pre">exclude_properties</span></tt> can also accommodate
446
 
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects to more accurately describe which columns
 
454
<a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects to more accurately describe which columns
447
455
should be included or excluded:</p>
448
456
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">UserAddress</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
449
457
    <span class="n">__table__</span> <span class="o">=</span> <span class="n">user_table</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">addresses_table</span><span class="p">)</span>
455
463
<div class="admonition note">
456
464
<p class="first admonition-title">Note</p>
457
465
<p class="last">insert and update defaults configured on individual
458
 
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects, i.e. those described at <a class="reference internal" href="../core/schema.html#metadata-defaults"><em>Column Insert/Update Defaults</em></a>
 
466
<a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects, i.e. those described at <em class="xref std std-ref">metadata_defaults</em>
459
467
including those configured by the <tt class="docutils literal"><span class="pre">default</span></tt>, <tt class="docutils literal"><span class="pre">update</span></tt>,
460
468
<tt class="docutils literal"><span class="pre">server_default</span></tt> and <tt class="docutils literal"><span class="pre">server_onupdate</span></tt> arguments, will continue to
461
 
function normally even if those <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects are not mapped.
 
469
function normally even if those <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects are not mapped.
462
470
This is because in the case of <tt class="docutils literal"><span class="pre">default</span></tt> and <tt class="docutils literal"><span class="pre">update</span></tt>, the
463
 
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object is still present on the underlying
464
 
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, thus allowing the default functions to take place when
 
471
<a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object is still present on the underlying
 
472
<a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, thus allowing the default functions to take place when
465
473
the ORM emits an INSERT or UPDATE, and in the case of <tt class="docutils literal"><span class="pre">server_default</span></tt>
466
474
and <tt class="docutils literal"><span class="pre">server_onupdate</span></tt>, the relational database itself maintains these
467
475
functions.</p>
492
500
    <span class="n">photo</span> <span class="o">=</span> <span class="n">deferred</span><span class="p">(</span><span class="n">Column</span><span class="p">(</span><span class="n">Binary</span><span class="p">))</span></pre></div>
493
501
</div>
494
502
<p>Classical mappings as always place the usage of <a class="reference internal" href="#sqlalchemy.orm.deferred" title="sqlalchemy.orm.deferred"><tt class="xref py py-func docutils literal"><span class="pre">orm.deferred()</span></tt></a> in the
495
 
<tt class="docutils literal"><span class="pre">properties</span></tt> dictionary against the table-bound <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>:</p>
 
503
<tt class="docutils literal"><span class="pre">properties</span></tt> dictionary against the table-bound <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>:</p>
496
504
<div class="highlight-python"><div class="highlight"><pre><span class="n">mapper</span><span class="p">(</span><span class="n">Book</span><span class="p">,</span> <span class="n">book_table</span><span class="p">,</span> <span class="n">properties</span><span class="o">=</span><span class="p">{</span>
497
505
    <span class="s">&#39;photo&#39;</span><span class="p">:</span><span class="n">deferred</span><span class="p">(</span><span class="n">book_table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">photo</span><span class="p">)</span>
498
506
<span class="p">})</span></pre></div>
694
702
must be distinguished from the Python expression, which can be achieved using
695
703
<a class="reference internal" href="extensions/hybrid.html#sqlalchemy.ext.hybrid.hybrid_property.expression" title="sqlalchemy.ext.hybrid.hybrid_property.expression"><tt class="xref py py-meth docutils literal"><span class="pre">hybrid_property.expression()</span></tt></a>.  Below we illustrate the case where a conditional
696
704
needs to be present inside the hybrid, using the <tt class="docutils literal"><span class="pre">if</span></tt> statement in Python and the
697
 
<a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.case" title="sqlalchemy.sql.expression.case"><tt class="xref py py-func docutils literal"><span class="pre">sql.expression.case()</span></tt></a> construct for SQL expressions:</p>
 
705
<a class="reference internal" href="../core/sqlelement.html#sqlalchemy.sql.expression.case" title="sqlalchemy.sql.expression.case"><tt class="xref py py-func docutils literal"><span class="pre">sql.expression.case()</span></tt></a> construct for SQL expressions:</p>
698
706
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.ext.hybrid</span> <span class="kn">import</span> <span class="n">hybrid_property</span>
699
707
<span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="kn">import</span> <span class="n">case</span>
700
708
 
721
729
<div class="section" id="using-column-property">
722
730
<span id="mapper-column-property-sql-expressions"></span><h3>Using column_property<a class="headerlink" href="#using-column-property" title="Permalink to this headline">¶</a></h3>
723
731
<p>The <a class="reference internal" href="#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 can be used to map a SQL
724
 
expression in a manner similar to a regularly mapped <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.
 
732
expression in a manner similar to a regularly mapped <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.
725
733
With this technique, the attribute is loaded
726
734
along with all other column-mapped attributes at load time.  This is in some
727
735
cases an advantage over the usage of hybrids, as the value can be loaded
744
752
    <span class="n">lastname</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">))</span>
745
753
    <span class="n">fullname</span> <span class="o">=</span> <span class="n">column_property</span><span class="p">(</span><span class="n">firstname</span> <span class="o">+</span> <span class="s">&quot; &quot;</span> <span class="o">+</span> <span class="n">lastname</span><span class="p">)</span></pre></div>
746
754
</div>
747
 
<p>Correlated subqueries may be used as well.  Below we use the <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>
 
755
<p>Correlated subqueries may be used as well.  Below we use the <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>
748
756
construct to create a SELECT that links together the count of <tt class="docutils literal"><span class="pre">Address</span></tt>
749
757
objects available for a particular <tt class="docutils literal"><span class="pre">User</span></tt>:</p>
750
758
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.orm</span> <span class="kn">import</span> <span class="n">column_property</span>
769
777
            <span class="n">correlate_except</span><span class="p">(</span><span class="n">Address</span><span class="p">)</span>
770
778
    <span class="p">)</span></pre></div>
771
779
</div>
772
 
<p>In the above example, we define a <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct like the following:</p>
 
780
<p>In the above example, we define a <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct like the following:</p>
773
781
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">func</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="n">Address</span><span class="o">.</span><span class="n">id</span><span class="p">)])</span><span class="o">.</span>\
774
782
    <span class="n">where</span><span class="p">(</span><span class="n">Address</span><span class="o">.</span><span class="n">user_id</span><span class="o">==</span><span class="nb">id</span><span class="p">)</span><span class="o">.</span>\
775
783
    <span class="n">correlate_except</span><span class="p">(</span><span class="n">Address</span><span class="p">)</span></pre></div>
776
784
</div>
777
785
<p>The meaning of the above statement is, select the count of <tt class="docutils literal"><span class="pre">Address.id</span></tt> rows
778
786
where the <tt class="docutils literal"><span class="pre">Address.user_id</span></tt> column is equated to <tt class="docutils literal"><span class="pre">id</span></tt>, which in the context
779
 
of the <tt class="docutils literal"><span class="pre">User</span></tt> class is the <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> named <tt class="docutils literal"><span class="pre">id</span></tt> (note that <tt class="docutils literal"><span class="pre">id</span></tt> is
 
787
of the <tt class="docutils literal"><span class="pre">User</span></tt> class is the <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> named <tt class="docutils literal"><span class="pre">id</span></tt> (note that <tt class="docutils literal"><span class="pre">id</span></tt> is
780
788
also the name of a Python built in function, which is not what we want to use
781
789
here - if we were outside of the <tt class="docutils literal"><span class="pre">User</span></tt> class definition, we&#8217;d use <tt class="docutils literal"><span class="pre">User.id</span></tt>).</p>
782
790
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">select.correlate_except()</span></tt> directive indicates that each element in the
783
 
FROM clause of this <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> may be omitted from the FROM list (that is, correlated
 
791
FROM clause of this <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> may be omitted from the FROM list (that is, correlated
784
792
to the enclosing SELECT statement against <tt class="docutils literal"><span class="pre">User</span></tt>) except for the one corresponding
785
793
to <tt class="docutils literal"><span class="pre">Address</span></tt>.  This isn&#8217;t strictly necessary, but prevents <tt class="docutils literal"><span class="pre">Address</span></tt> from
786
794
being inadvertently omitted from the FROM list in the case of a long string
795
803
            <span class="n">where</span><span class="p">(</span><span class="n">Address</span><span class="o">.</span><span class="n">user_id</span><span class="o">==</span><span class="n">User</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
796
804
    <span class="p">)</span></pre></div>
797
805
</div>
798
 
<p>For many-to-many relationships, use <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.and_" title="sqlalchemy.sql.expression.and_"><tt class="xref py py-func docutils literal"><span class="pre">and_()</span></tt></a> to join the fields of the
 
806
<p>For many-to-many relationships, use <a class="reference internal" href="../core/sqlelement.html#sqlalchemy.sql.expression.and_" title="sqlalchemy.sql.expression.and_"><tt class="xref py py-func docutils literal"><span class="pre">and_()</span></tt></a> to join the fields of the
799
807
association table to both tables in a relation, illustrated
800
808
here with a classical mapping:</p>
801
809
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">and_</span>
908
916
<li><strong>include_removes</strong> &#8211; <p>if True, &#8220;remove&#8221; events will be
909
917
sent as well - the validation function must accept an additional
910
918
argument &#8220;is_remove&#8221; which will be a boolean.</p>
911
 
<p class="versionadded">
912
 
<span class="versionmodified">New in version 0.7.7.</span></p>
 
919
<div class="versionadded">
 
920
<p><span>New in version 0.7.7.</span></p>
 
921
</div>
913
922
</li>
914
923
</ul>
915
924
</td>
1037
1046
<h3>Synonyms<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
1038
1047
<p>Synonyms are a mapper-level construct that applies expression behavior to a descriptor
1039
1048
based attribute.</p>
1040
 
<p class="versionchanged">
1041
 
<span class="versionmodified">Changed in version 0.7: </span>The functionality of synonym is superceded as of 0.7 by hybrid attributes.</p>
 
1049
<div class="versionchanged">
 
1050
<p><span>Changed in version 0.7: </span>The functionality of synonym is superceded as of 0.7 by hybrid attributes.</p>
 
1051
</div>
1042
1052
<dl class="function">
1043
1053
<dt id="sqlalchemy.orm.synonym">
1044
1054
<tt class="descclassname">sqlalchemy.orm.</tt><tt class="descname">synonym</tt><big>(</big><em>name</em>, <em>map_column=False</em>, <em>descriptor=None</em>, <em>comparator_factory=None</em>, <em>doc=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.synonym" title="Permalink to this definition">¶</a></dt>
1045
1055
<dd><p>Denote an attribute name as a synonym to a mapped property.</p>
1046
 
<p class="versionchanged">
1047
 
<span class="versionmodified">Changed in version 0.7: </span><a class="reference internal" href="#sqlalchemy.orm.synonym" title="sqlalchemy.orm.synonym"><tt class="xref py py-func docutils literal"><span class="pre">synonym()</span></tt></a> is superseded by the <a class="reference internal" href="extensions/hybrid.html#module-sqlalchemy.ext.hybrid" title="sqlalchemy.ext.hybrid"><tt class="xref py py-mod docutils literal"><span class="pre">hybrid</span></tt></a>
 
1056
<div class="versionchanged">
 
1057
<p><span>Changed in version 0.7: </span><a class="reference internal" href="#sqlalchemy.orm.synonym" title="sqlalchemy.orm.synonym"><tt class="xref py py-func docutils literal"><span class="pre">synonym()</span></tt></a> is superseded by the <a class="reference internal" href="extensions/hybrid.html#module-sqlalchemy.ext.hybrid" title="sqlalchemy.ext.hybrid"><tt class="xref py py-mod docutils literal"><span class="pre">hybrid</span></tt></a>
1048
1058
extension.  See  the documentation for hybrids
1049
1059
at <a class="reference internal" href="extensions/hybrid.html"><em>Hybrid Attributes</em></a>.</p>
 
1060
</div>
1050
1061
<p>Used with the <tt class="docutils literal"><span class="pre">properties</span></tt> dictionary sent to
1051
1062
<a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a>:</p>
1052
1063
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
1108
1119
<p>Sets of columns can be associated with a single user-defined datatype. The ORM
1109
1120
provides a single attribute which represents the group of columns using the
1110
1121
class you provide.</p>
1111
 
<p class="versionchanged">
1112
 
<span class="versionmodified">Changed in version 0.7: </span>Composites have been simplified such that
 
1122
<div class="versionchanged">
 
1123
<p><span>Changed in version 0.7: </span>Composites have been simplified such that
1113
1124
they no longer &#8220;conceal&#8221; the underlying column based attributes.  Additionally,
1114
1125
in-place mutation is no longer automatic; see the section below on
1115
1126
enabling mutability to support tracking of in-place changes.</p>
 
1127
</div>
1116
1128
<p>A simple example represents pairs of columns as a <tt class="docutils literal"><span class="pre">Point</span></tt> object.
1117
1129
<tt class="docutils literal"><span class="pre">Point</span></tt> represents such a pair as <tt class="docutils literal"><span class="pre">.x</span></tt> and <tt class="docutils literal"><span class="pre">.y</span></tt>:</p>
1118
1130
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Point</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
1141
1153
also should supply adequate <tt class="docutils literal"><span class="pre">__eq__()</span></tt> and <tt class="docutils literal"><span class="pre">__ne__()</span></tt> methods which test
1142
1154
the equality of two instances.</p>
1143
1155
<p>We will create a mapping to a table <tt class="docutils literal"><span class="pre">vertice</span></tt>, which represents two points
1144
 
as <tt class="docutils literal"><span class="pre">x1/y1</span></tt> and <tt class="docutils literal"><span class="pre">x2/y2</span></tt>. These are created normally as <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
 
1156
as <tt class="docutils literal"><span class="pre">x1/y1</span></tt> and <tt class="docutils literal"><span class="pre">x2/y2</span></tt>. These are created normally as <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
1145
1157
objects. Then, the <a class="reference internal" href="#sqlalchemy.orm.composite" title="sqlalchemy.orm.composite"><tt class="xref py py-func docutils literal"><span class="pre">composite()</span></tt></a> function is used to assign new
1146
1158
attributes that will represent sets of columns via the <tt class="docutils literal"><span class="pre">Point</span></tt> class:</p>
1147
1159
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Column</span><span class="p">,</span> <span class="n">Integer</span>
1206
1218
<li><strong>active_history=False</strong> &#8211; <p>When <tt class="docutils literal"><span class="pre">True</span></tt>, indicates that the &#8220;previous&#8221; value for a
1207
1219
scalar attribute should be loaded when replaced, if not
1208
1220
already loaded.  See the same flag on <a class="reference internal" href="#sqlalchemy.orm.column_property" title="sqlalchemy.orm.column_property"><tt class="xref py py-func docutils literal"><span class="pre">column_property()</span></tt></a>.</p>
1209
 
<p class="versionchanged">
1210
 
<span class="versionmodified">Changed in version 0.7: </span>This flag specifically becomes meaningful
 
1221
<div class="versionchanged">
 
1222
<p><span>Changed in version 0.7: </span>This flag specifically becomes meaningful
1211
1223
- previously it was a placeholder.</p>
 
1224
</div>
1212
1225
</li>
1213
1226
<li><strong>group</strong> &#8211; A group name for this property when marked as deferred.</li>
1214
1227
<li><strong>deferred</strong> &#8211; When True, the column property is &#8220;deferred&#8221;, meaning that it does not
1221
1234
class-bound descriptor.</li>
1222
1235
<li><strong>info</strong> &#8211; <p>Optional data dictionary which will be populated into the
1223
1236
<a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces.MapperProperty.info" title="sqlalchemy.orm.interfaces.MapperProperty.info"><tt class="xref py py-attr docutils literal"><span class="pre">MapperProperty.info</span></tt></a> attribute of this object.</p>
1224
 
<p class="versionadded">
1225
 
<span class="versionmodified">New in version 0.8.</span></p>
 
1237
<div class="versionadded">
 
1238
<p><span>New in version 0.8.</span></p>
 
1239
</div>
1226
1240
</li>
1227
1241
<li><strong>extension</strong> &#8211; an <a class="reference internal" href="deprecated.html#sqlalchemy.orm.interfaces.AttributeExtension" title="sqlalchemy.orm.interfaces.AttributeExtension"><tt class="xref py py-class docutils literal"><span class="pre">AttributeExtension</span></tt></a> instance,
1228
1242
or list of extensions, which will be prepended to the list of
1243
1257
via the usage of the <a class="reference internal" href="extensions/mutable.html#sqlalchemy.ext.mutable.MutableComposite" title="sqlalchemy.ext.mutable.MutableComposite"><tt class="xref py py-class docutils literal"><span class="pre">MutableComposite</span></tt></a> mixin, which uses events
1244
1258
to associate each user-defined composite object with all parent associations.
1245
1259
Please see the example in <a class="reference internal" href="extensions/mutable.html#mutable-composites"><em>Establishing Mutability on Composites</em></a>.</p>
1246
 
<p class="versionchanged">
1247
 
<span class="versionmodified">Changed in version 0.7: </span>In-place changes to an existing composite value are no longer
 
1260
<div class="versionchanged">
 
1261
<p><span>Changed in version 0.7: </span>In-place changes to an existing composite value are no longer
1248
1262
tracked automatically; the functionality is superseded by the
1249
1263
<a class="reference internal" href="extensions/mutable.html#sqlalchemy.ext.mutable.MutableComposite" title="sqlalchemy.ext.mutable.MutableComposite"><tt class="xref py py-class docutils literal"><span class="pre">MutableComposite</span></tt></a> class.</p>
1250
1264
</div>
 
1265
</div>
1251
1266
<div class="section" id="redefining-comparison-operations-for-composites">
1252
1267
<span id="composite-operations"></span><h3>Redefining Comparison Operations for Composites<a class="headerlink" href="#redefining-comparison-operations-for-composites" title="Permalink to this headline">¶</a></h3>
1253
1268
<p>The &#8220;equals&#8221; comparison operation by default produces an AND of all
1287
1302
<div class="section" id="mapping-a-class-against-multiple-tables">
1288
1303
<span id="maptojoin"></span><h2>Mapping a Class against Multiple Tables<a class="headerlink" href="#mapping-a-class-against-multiple-tables" title="Permalink to this headline">¶</a></h2>
1289
1304
<p>Mappers can be constructed against arbitrary relational units (called
1290
 
<em>selectables</em>) in addition to plain tables. For example, the <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.join" title="sqlalchemy.sql.expression.join"><tt class="xref py py-func docutils literal"><span class="pre">join()</span></tt></a>
 
1305
<em>selectables</em>) in addition to plain tables. For example, the <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.join" title="sqlalchemy.sql.expression.join"><tt class="xref py py-func docutils literal"><span class="pre">join()</span></tt></a>
1291
1306
function creates a selectable unit comprised of
1292
1307
multiple tables, complete with its own composite primary key, which can be
1293
 
mapped in the same way as a <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>:</p>
 
1308
mapped in the same way as a <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>:</p>
1294
1309
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">Column</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> \
1295
1310
        <span class="n">String</span><span class="p">,</span> <span class="n">MetaData</span><span class="p">,</span> <span class="n">join</span><span class="p">,</span> <span class="n">ForeignKey</span>
1296
1311
<span class="kn">from</span> <span class="nn">sqlalchemy.ext.declarative</span> <span class="kn">import</span> <span class="n">declarative_base</span>
1346
1361
</div>
1347
1362
<div class="section" id="mapping-a-class-against-arbitrary-selects">
1348
1363
<h2>Mapping a Class against Arbitrary Selects<a class="headerlink" href="#mapping-a-class-against-arbitrary-selects" title="Permalink to this headline">¶</a></h2>
1349
 
<p>Similar to mapping against a join, a plain <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> object can be used with a
 
1364
<p>Similar to mapping against a join, a plain <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> object can be used with a
1350
1365
mapper as well.  The example fragment below illustrates mapping a class
1351
 
called <tt class="docutils literal"><span class="pre">Customer</span></tt> to a <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> which includes a join to a
 
1366
called <tt class="docutils literal"><span class="pre">Customer</span></tt> to a <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> which includes a join to a
1352
1367
subquery:</p>
1353
1368
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">select</span><span class="p">,</span> <span class="n">func</span>
1354
1369
 
1396
1411
<h2>Multiple Mappers for One Class<a class="headerlink" href="#multiple-mappers-for-one-class" title="Permalink to this headline">¶</a></h2>
1397
1412
<p>In modern SQLAlchemy, a particular class is only mapped by one <a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a>
1398
1413
at a time.  The rationale here is that the <a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a> modifies the class itself, not only
1399
 
persisting it towards a particular <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, but also <em>instrumenting</em>
 
1414
persisting it towards a particular <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, but also <em>instrumenting</em>
1400
1415
attributes upon the class which are structured specifically according to the
1401
1416
table metadata.</p>
1402
1417
<p>One potential use case for another mapper to exist at the same time is if we
1403
 
wanted to load instances of our class not just from the immediate <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
 
1418
wanted to load instances of our class not just from the immediate <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
1404
1419
to which it is mapped, but from another selectable that is a derivation of that
1405
 
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.   While there technically is a way to create such a <a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a>,
 
1420
<a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.   While there technically is a way to create such a <a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a>,
1406
1421
using the <tt class="docutils literal"><span class="pre">non_primary=True</span></tt> option, this approach is virtually never needed.
1407
1422
Instead, we use the functionality of the <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a> object to achieve this,
1408
1423
using a method such as <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query.select_from" title="sqlalchemy.orm.query.Query.select_from"><tt class="xref py py-meth docutils literal"><span class="pre">Query.select_from()</span></tt></a>
1417
1432
pattern, which is described as a recipe at <a class="reference external" href="http://www.sqlalchemy.org/trac/wiki/UsageRecipes/EntityName">Entity Name</a>.</p>
1418
1433
</div>
1419
1434
<div class="section" id="constructors-and-object-initialization">
1420
 
<h2>Constructors and Object Initialization<a class="headerlink" href="#constructors-and-object-initialization" title="Permalink to this headline">¶</a></h2>
 
1435
<span id="mapping-constructors"></span><h2>Constructors and Object Initialization<a class="headerlink" href="#constructors-and-object-initialization" title="Permalink to this headline">¶</a></h2>
1421
1436
<p>Mapping imposes no restrictions or requirements on the constructor
1422
1437
(<tt class="docutils literal"><span class="pre">__init__</span></tt>) method for the class. You are free to require any arguments for
1423
1438
the function that you wish, assign attributes to the instance that are unknown
1479
1494
</dd></dl>
1480
1495
 
1481
1496
</div>
 
1497
<div class="section" id="configuring-a-version-counter">
 
1498
<span id="mapper-version-counter"></span><h2>Configuring a Version Counter<a class="headerlink" href="#configuring-a-version-counter" title="Permalink to this headline">¶</a></h2>
 
1499
<p>The <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> supports management of a <em class="xref std std-term">version id column</em>, which
 
1500
is a single table column that increments or otherwise updates its value
 
1501
each time an <tt class="docutils literal"><span class="pre">UPDATE</span></tt> to the mapped table occurs.  This value is checked each
 
1502
time the ORM emits an <tt class="docutils literal"><span class="pre">UPDATE</span></tt> or <tt class="docutils literal"><span class="pre">DELETE</span></tt> against the row to ensure that
 
1503
the value held in memory matches the database value.</p>
 
1504
<p>The purpose of this feature is to detect when two concurrent transactions
 
1505
are modifying the same row at roughly the same time, or alternatively to provide
 
1506
a guard against the usage of a &#8220;stale&#8221; row in a system that might be re-using
 
1507
data from a previous transaction without refreshing (e.g. if one sets <tt class="docutils literal"><span class="pre">expire_on_commit=False</span></tt>
 
1508
with a <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a>, it is possible to re-use the data from a previous
 
1509
transaction).</p>
 
1510
<div class="topic">
 
1511
<p class="topic-title first">Concurrent transaction updates</p>
 
1512
<p>When detecting concurrent updates within transactions, it is typically the
 
1513
case that the database&#8217;s transaction isolation level is below the level of
 
1514
<em class="xref std std-term">repeatable read</em>; otherwise, the transaction will not be exposed
 
1515
to a new row value created by a concurrent update which conflicts with
 
1516
the locally updated value.  In this case, the SQLAlchemy versioning
 
1517
feature will typically not be useful for in-transaction conflict detection,
 
1518
though it still can be used for cross-transaction staleness detection.</p>
 
1519
<p>The database that enforces repeatable reads will typically either have locked the
 
1520
target row against a concurrent update, or is employing some form
 
1521
of multi version concurrency control such that it will emit an error
 
1522
when the transaction is committed.  SQLAlchemy&#8217;s version_id_col is an alternative
 
1523
which allows version tracking to occur for specific tables within a transaction
 
1524
that otherwise might not have this isolation level set.</p>
 
1525
<div class="admonition seealso">
 
1526
<p class="first admonition-title">See also</p>
 
1527
<p class="last"><a class="reference external" href="http://www.postgresql.org/docs/9.1/static/transaction-iso.html#XACT-REPEATABLE-READ">Repeatable Read Isolation Level</a> - Postgresql&#8217;s implementation of repeatable read, including a description of the error condition.</p>
 
1528
</div>
 
1529
</div>
 
1530
<div class="section" id="simple-version-counting">
 
1531
<h3>Simple Version Counting<a class="headerlink" href="#simple-version-counting" title="Permalink to this headline">¶</a></h3>
 
1532
<p>The most straightforward way to track versions is to add an integer column
 
1533
to the mapped table, then establish it as the <tt class="docutils literal"><span class="pre">version_id_col</span></tt> within the
 
1534
mapper options:</p>
 
1535
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
 
1536
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;user&#39;</span>
 
1537
 
 
1538
    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
 
1539
    <span class="n">version_id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
 
1540
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
 
1541
 
 
1542
    <span class="n">__mapper_args__</span> <span class="o">=</span> <span class="p">{</span>
 
1543
        <span class="s">&quot;version_id_col&quot;</span><span class="p">:</span> <span class="n">version_id</span>
 
1544
    <span class="p">}</span></pre></div>
 
1545
</div>
 
1546
<p>Above, the <tt class="docutils literal"><span class="pre">User</span></tt> mapping tracks integer versions using the column
 
1547
<tt class="docutils literal"><span class="pre">version_id</span></tt>.   When an object of type <tt class="docutils literal"><span class="pre">User</span></tt> is first flushed, the
 
1548
<tt class="docutils literal"><span class="pre">version_id</span></tt> column will be given a value of &#8220;1&#8221;.   Then, an UPDATE
 
1549
of the table later on will always be emitted in a manner similar to the
 
1550
following:</p>
 
1551
<div class="highlight-python"><pre>UPDATE user SET version_id=:version_id, name=:name
 
1552
WHERE user.id = :user_id AND user.version_id = :user_version_id
 
1553
{"name": "new name", "version_id": 2, "user_id": 1, "user_version_id": 1}</pre>
 
1554
</div>
 
1555
<p>The above UPDATE statement is updating the row that not only matches
 
1556
<tt class="docutils literal"><span class="pre">user.id</span> <span class="pre">=</span> <span class="pre">1</span></tt>, it also is requiring that <tt class="docutils literal"><span class="pre">user.version_id</span> <span class="pre">=</span> <span class="pre">1</span></tt>, where &#8220;1&#8221;
 
1557
is the last version identifier we&#8217;ve been known to use on this object.
 
1558
If a transaction elsewhere has modifed the row independently, this version id
 
1559
will no longer match, and the UPDATE statement will report that no rows matched;
 
1560
this is the condition that SQLAlchemy tests, that exactly one row matched our
 
1561
UPDATE (or DELETE) statement.  If zero rows match, that indicates our version
 
1562
of the data is stale, and a <tt class="xref py py-class docutils literal"><span class="pre">StaleDataError</span></tt> is raised.</p>
 
1563
</div>
 
1564
<div class="section" id="custom-version-counters-types">
 
1565
<span id="custom-version-counter"></span><h3>Custom Version Counters / Types<a class="headerlink" href="#custom-version-counters-types" title="Permalink to this headline">¶</a></h3>
 
1566
<p>Other kinds of values or counters can be used for versioning.  Common types include
 
1567
dates and GUIDs.   When using an alternate type or counter scheme, SQLAlchemy
 
1568
provides a hook for this scheme using the <tt class="docutils literal"><span class="pre">version_id_generator</span></tt> argument,
 
1569
which accepts a version generation callable.  This callable is passed the value of the current
 
1570
known version, and is expected to return the subsequent version.</p>
 
1571
<p>For example, if we wanted to track the versioning of our <tt class="docutils literal"><span class="pre">User</span></tt> class
 
1572
using a randomly generated GUID, we could do this (note that some backends
 
1573
support a native GUID type, but we illustrate here using a simple string):</p>
 
1574
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">uuid</span>
 
1575
 
 
1576
<span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
 
1577
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;user&#39;</span>
 
1578
 
 
1579
    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
 
1580
    <span class="n">version_uuid</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">32</span><span class="p">))</span>
 
1581
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
 
1582
 
 
1583
    <span class="n">__mapper_args__</span> <span class="o">=</span> <span class="p">{</span>
 
1584
        <span class="s">&#39;version_id_col&#39;</span><span class="p">:</span><span class="n">version_uuid</span><span class="p">,</span>
 
1585
        <span class="s">&#39;version_id_generator&#39;</span><span class="p">:</span><span class="k">lambda</span> <span class="n">version</span><span class="p">:</span> <span class="n">uuid</span><span class="o">.</span><span class="n">uuid4</span><span class="p">()</span><span class="o">.</span><span class="n">hex</span>
 
1586
    <span class="p">}</span></pre></div>
 
1587
</div>
 
1588
<p>The persistence engine will call upon <tt class="docutils literal"><span class="pre">uuid.uuid4()</span></tt> each time a
 
1589
<tt class="docutils literal"><span class="pre">User</span></tt> object is subject to an INSERT or an UPDATE.  In this case, our
 
1590
version generation function can disregard the incoming value of <tt class="docutils literal"><span class="pre">version</span></tt>,
 
1591
as the <tt class="docutils literal"><span class="pre">uuid4()</span></tt> function
 
1592
generates identifiers without any prerequisite value.  If we were using
 
1593
a sequential versioning scheme such as numeric or a special character system,
 
1594
we could make use of the given <tt class="docutils literal"><span class="pre">version</span></tt> in order to help determine the
 
1595
subsequent value.</p>
 
1596
<div class="admonition seealso">
 
1597
<p class="first admonition-title">See also</p>
 
1598
<p class="last"><a class="reference internal" href="../core/types.html#custom-guid-type"><em>Backend-agnostic GUID Type</em></a></p>
 
1599
</div>
 
1600
</div>
 
1601
</div>
1482
1602
<div class="section" id="class-mapping-api">
1483
1603
<h2>Class Mapping API<a class="headerlink" href="#class-mapping-api" title="Permalink to this headline">¶</a></h2>
1484
1604
<dl class="function">
1531
1651
<li><strong>class_</strong> &#8211; The class to be mapped.  When using Declarative,
1532
1652
this argument is automatically passed as the declared class
1533
1653
itself.</li>
1534
 
<li><strong>local_table</strong> &#8211; The <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> or other selectable
 
1654
<li><strong>local_table</strong> &#8211; The <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> or other selectable
1535
1655
to which the class is mapped.  May be <tt class="docutils literal"><span class="pre">None</span></tt> if
1536
1656
this mapper inherits from another mapper using single-table
1537
1657
inheritance.   When using Declarative, this argument is
1538
1658
automatically passed by the extension, based on what
1539
1659
is configured via the <tt class="docutils literal"><span class="pre">__table__</span></tt> argument or via the
1540
 
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> produced as a result of the <tt class="docutils literal"><span class="pre">__tablename__</span></tt>
1541
 
and <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> arguments present.</li>
 
1660
<a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> produced as a result of the <tt class="docutils literal"><span class="pre">__tablename__</span></tt>
 
1661
and <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> arguments present.</li>
1542
1662
<li><strong>always_refresh</strong> &#8211; If True, all query operations for this mapped
1543
1663
class will overwrite all data within object instances that already
1544
1664
exist within the session, erasing any in-memory changes with
1560
1680
<a class="reference internal" href="events.html#sqlalchemy.orm.events.MapperEvents" title="sqlalchemy.orm.events.MapperEvents"><tt class="xref py py-class docutils literal"><span class="pre">MapperEvents</span></tt></a> listener requires being called
1561
1681
in between individual row persistence operations.</li>
1562
1682
<li><strong>column_prefix</strong> &#8211; <p>A string which will be prepended
1563
 
to the mapped attribute name when <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
 
1683
to the mapped attribute name when <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
1564
1684
objects are automatically assigned as attributes to the
1565
1685
mapped class.  Does not affect explicitly specified
1566
1686
column-based properties.</p>
1570
1690
table inheritance with its parent mapper.</p>
1571
1691
<p>See the section <a class="reference internal" href="inheritance.html#concrete-inheritance"><em>Concrete Table Inheritance</em></a> for an example.</p>
1572
1692
</li>
 
1693
<li><strong>eager_defaults</strong> &#8211; if True, the ORM will immediately fetch the
 
1694
value of server-generated default values after an INSERT or UPDATE,
 
1695
rather than leaving them as expired to be fetched on next access.
 
1696
This can be used for event schemes where the server-generated values
 
1697
are needed immediately before the flush completes.
 
1698
This scheme will emit an individual <tt class="docutils literal"><span class="pre">SELECT</span></tt> statement per row
 
1699
inserted or updated, which note can add significant performance
 
1700
overhead.</li>
1573
1701
<li><strong>exclude_properties</strong> &#8211; <p>A list or set of string column names to
1574
1702
be excluded from mapping.</p>
1575
1703
<p>See <a class="reference internal" href="#include-exclude-cols"><em>Mapping a Subset of Table Columns</em></a> for an example.</p>
1588
1716
of the other mapper&#8217;s class.   When using Declarative, this argument
1589
1717
is passed automatically as a result of the natural class
1590
1718
hierarchy of the declared classes.</p>
1591
 
<p>See also:</p>
1592
 
<p><a class="reference internal" href="inheritance.html"><em>Mapping Class Inheritance Hierarchies</em></a></p>
 
1719
<div class="admonition seealso">
 
1720
<p class="first admonition-title">See also</p>
 
1721
<p class="last"><a class="reference internal" href="inheritance.html"><em>Mapping Class Inheritance Hierarchies</em></a></p>
 
1722
</div>
1593
1723
</li>
1594
1724
<li><strong>inherit_condition</strong> &#8211; For joined table inheritance, a SQL
1595
1725
expression which will
1596
1726
define how the two tables are joined; defaults to a natural join
1597
1727
between the two tables.</li>
1598
1728
<li><strong>inherit_foreign_keys</strong> &#8211; When <tt class="docutils literal"><span class="pre">inherit_condition</span></tt> is used and the
1599
 
columns present are missing a <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> configuration,
 
1729
columns present are missing a <a class="reference internal" href="../core/constraints.html#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> configuration,
1600
1730
this parameter can be used to specify which columns are &#8220;foreign&#8221;.
1601
1731
In most cases can be left as <tt class="docutils literal"><span class="pre">None</span></tt>.</li>
1602
1732
<li><strong>legacy_is_orphan</strong> &#8211; <p>Boolean, defaults to <tt class="docutils literal"><span class="pre">False</span></tt>.
1613
1743
object has been flushed yet or not.</p>
1614
1744
<p>See the change note and example at <a class="reference internal" href="../changelog/migration_08.html#legacy-is-orphan-addition"><em>The consideration of a &#8220;pending&#8221; object as an &#8220;orphan&#8221; has been made more aggressive</em></a>
1615
1745
for more detail on this change.</p>
1616
 
<p class="versionadded">
1617
 
<span class="versionmodified">New in version 0.8: </span>- the consideration of a pending object as
 
1746
<div class="versionadded">
 
1747
<p><span>New in version 0.8: </span>- the consideration of a pending object as
1618
1748
an &#8220;orphan&#8221; has been modified to more closely match the
1619
1749
behavior as that of persistent objects, which is that the object
1620
1750
is expunged from the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> as soon as it is
1623
1753
from all of its orphan-enabled parents. The new flag <tt class="docutils literal"><span class="pre">legacy_is_orphan</span></tt>
1624
1754
is added to <a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">orm.mapper()</span></tt></a> which re-establishes the
1625
1755
legacy behavior.</p>
 
1756
</div>
1626
1757
</li>
1627
1758
<li><strong>non_primary</strong> &#8211; <p>Specify that this <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> is in addition
1628
1759
to the &#8220;primary&#8221; mapper, that is, the one used for persistence.
1632
1763
<p>The <tt class="docutils literal"><span class="pre">non_primary</span></tt> feature is rarely needed with modern
1633
1764
usage.</p>
1634
1765
</li>
1635
 
<li><strong>order_by</strong> &#8211; A single <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> or list of <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
 
1766
<li><strong>order_by</strong> &#8211; A single <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> or list of <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
1636
1767
objects for which selection operations should use as the default
1637
1768
ordering for entities.  By default mappers have no pre-defined
1638
1769
ordering.</li>
1648
1779
operation for an update.  The <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> here will
1649
1780
emit an UPDATE statement for the dependent columns during a
1650
1781
primary key change.</p>
1651
 
<p>See also:</p>
1652
 
<p><a class="reference internal" href="relationships.html#passive-updates"><em>Mutable Primary Keys / Update Cascades</em></a> - description of a similar feature as
 
1782
<div class="admonition seealso">
 
1783
<p class="first admonition-title">See also</p>
 
1784
<p class="last"><a class="reference internal" href="relationships.html#passive-updates"><em>Mutable Primary Keys / Update Cascades</em></a> - description of a similar feature as
1653
1785
used with <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></p>
 
1786
</div>
1654
1787
</li>
1655
1788
<li><strong>polymorphic_on</strong> &#8211; <p>Specifies the column, attribute, or
1656
1789
SQL expression used to determine the target class for an
1657
1790
incoming row, when inheriting classes are present.</p>
1658
 
<p>This value is commonly a <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object that&#8217;s
1659
 
present in the mapped <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>:</p>
 
1791
<p>This value is commonly a <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object that&#8217;s
 
1792
present in the mapped <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>:</p>
1660
1793
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Employee</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
1661
1794
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;employee&#39;</span>
1662
1795
 
1670
1803
</div>
1671
1804
<p>It may also be specified
1672
1805
as a SQL expression, as in this example where we
1673
 
use the <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.case" title="sqlalchemy.sql.expression.case"><tt class="xref py py-func docutils literal"><span class="pre">case()</span></tt></a> construct to provide a conditional
 
1806
use the <a class="reference internal" href="../core/sqlelement.html#sqlalchemy.sql.expression.case" title="sqlalchemy.sql.expression.case"><tt class="xref py py-func docutils literal"><span class="pre">case()</span></tt></a> construct to provide a conditional
1674
1807
approach:</p>
1675
1808
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Employee</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
1676
1809
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;employee&#39;</span>
1706
1839
        <span class="s">&quot;polymorphic_identity&quot;</span><span class="p">:</span><span class="s">&quot;employee&quot;</span>
1707
1840
    <span class="p">}</span></pre></div>
1708
1841
</div>
1709
 
<p class="versionchanged">
1710
 
<span class="versionmodified">Changed in version 0.7.4: </span><tt class="docutils literal"><span class="pre">polymorphic_on</span></tt> may be specified as a SQL expression,
 
1842
<div class="versionchanged">
 
1843
<p><span>Changed in version 0.7.4: </span><tt class="docutils literal"><span class="pre">polymorphic_on</span></tt> may be specified as a SQL expression,
1711
1844
or refer to any attribute configured with
1712
1845
<a class="reference internal" href="#sqlalchemy.orm.column_property" title="sqlalchemy.orm.column_property"><tt class="xref py py-func docutils literal"><span class="pre">column_property()</span></tt></a>, or to the string name of one.</p>
 
1846
</div>
1713
1847
<p>When setting <tt class="docutils literal"><span class="pre">polymorphic_on</span></tt> to reference an
1714
1848
attribute or expression that&#8217;s not present in the
1715
 
locally mapped <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, yet the value
 
1849
locally mapped <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, yet the value
1716
1850
of the discriminator should be persisted to the database,
1717
1851
the value of the
1718
1852
discriminator is not automatically set on new
1732
1866
for the mapped class to the <tt class="docutils literal"><span class="pre">discriminator</span></tt> attribute,
1733
1867
thus persisting the value to the <tt class="docutils literal"><span class="pre">discriminator</span></tt> column
1734
1868
in the database.</p>
1735
 
<p>See also:</p>
1736
 
<p><a class="reference internal" href="inheritance.html"><em>Mapping Class Inheritance Hierarchies</em></a></p>
 
1869
<div class="admonition seealso">
 
1870
<p class="first admonition-title">See also</p>
 
1871
<p class="last"><a class="reference internal" href="inheritance.html"><em>Mapping Class Inheritance Hierarchies</em></a></p>
 
1872
</div>
1737
1873
</li>
1738
1874
<li><strong>polymorphic_identity</strong> &#8211; Specifies the value which
1739
1875
identifies this particular class as returned by the
1744
1880
be used for the newly reconstructed object.</li>
1745
1881
<li><strong>properties</strong> &#8211; A dictionary mapping the string names of object
1746
1882
attributes to <a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces.MapperProperty" title="sqlalchemy.orm.interfaces.MapperProperty"><tt class="xref py py-class docutils literal"><span class="pre">MapperProperty</span></tt></a> instances, which define the
1747
 
persistence behavior of that attribute.  Note that <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
 
1883
persistence behavior of that attribute.  Note that <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
1748
1884
objects present in
1749
 
the mapped <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> are automatically placed into
 
1885
the mapped <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> are automatically placed into
1750
1886
<tt class="docutils literal"><span class="pre">ColumnProperty</span></tt> instances upon mapping, unless overridden.
1751
1887
When using Declarative, this argument is passed automatically,
1752
1888
based on all those <a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces.MapperProperty" title="sqlalchemy.orm.interfaces.MapperProperty"><tt class="xref py py-class docutils literal"><span class="pre">MapperProperty</span></tt></a> instances declared
1753
1889
in the declared class body.</li>
1754
 
<li><strong>primary_key</strong> &#8211; A list of <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects which define the
 
1890
<li><strong>primary_key</strong> &#8211; A list of <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects which define the
1755
1891
primary key to be used against this mapper&#8217;s selectable unit.
1756
1892
This is normally simply the primary key of the <tt class="docutils literal"><span class="pre">local_table</span></tt>, but
1757
1893
can be overridden here.</li>
1758
 
<li><strong>version_id_col</strong> &#8211; A <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
1759
 
that will be used to keep a running version id of mapped entities
1760
 
in the database.  This is used during save operations to ensure that
1761
 
no other thread or process has updated the instance during the
1762
 
lifetime of the entity, else a
 
1894
<li><strong>version_id_col</strong> &#8211; <p>A <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
 
1895
that will be used to keep a running version id of rows
 
1896
in the table.  This is used to detect concurrent updates or
 
1897
the presence of stale data in a flush.  The methodology is to
 
1898
detect if an UPDATE statement does not match the last known
 
1899
version id, a
1763
1900
<a class="reference internal" href="exceptions.html#sqlalchemy.orm.exc.StaleDataError" title="sqlalchemy.orm.exc.StaleDataError"><tt class="xref py py-class docutils literal"><span class="pre">StaleDataError</span></tt></a> exception is
1764
 
thrown.  By default the column must be of <a class="reference internal" href="../core/types.html#sqlalchemy.types.Integer" title="sqlalchemy.types.Integer"><tt class="xref py py-class docutils literal"><span class="pre">Integer</span></tt></a> type,
1765
 
unless <tt class="docutils literal"><span class="pre">version_id_generator</span></tt> specifies a new generation
1766
 
algorithm.</li>
1767
 
<li><strong>version_id_generator</strong> &#8211; <p>A callable which defines the algorithm
1768
 
used to generate new version ids. Defaults to an integer
1769
 
generator. Can be replaced with one that generates timestamps,
1770
 
uuids, etc. e.g.:</p>
1771
 
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">uuid</span>
1772
 
 
1773
 
<span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
1774
 
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;mytable&#39;</span>
1775
 
    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
1776
 
    <span class="n">version_uuid</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">32</span><span class="p">))</span>
1777
 
 
1778
 
    <span class="n">__mapper_args__</span> <span class="o">=</span> <span class="p">{</span>
1779
 
        <span class="s">&#39;version_id_col&#39;</span><span class="p">:</span><span class="n">version_uuid</span><span class="p">,</span>
1780
 
        <span class="s">&#39;version_id_generator&#39;</span><span class="p">:</span><span class="k">lambda</span> <span class="n">version</span><span class="p">:</span><span class="n">uuid</span><span class="o">.</span><span class="n">uuid4</span><span class="p">()</span><span class="o">.</span><span class="n">hex</span>
1781
 
    <span class="p">}</span></pre></div>
1782
 
</div>
1783
 
<p>The callable receives the current version identifier as its
1784
 
single argument.</p>
 
1901
thrown.
 
1902
By default, the column must be of <a class="reference internal" href="../core/types.html#sqlalchemy.types.Integer" title="sqlalchemy.types.Integer"><tt class="xref py py-class docutils literal"><span class="pre">Integer</span></tt></a> type,
 
1903
unless <tt class="docutils literal"><span class="pre">version_id_generator</span></tt> specifies an alternative version
 
1904
generator.</p>
 
1905
<div class="admonition seealso">
 
1906
<p class="first admonition-title">See also</p>
 
1907
<p class="last"><a class="reference internal" href="#mapper-version-counter"><em>Configuring a Version Counter</em></a> - discussion of version counting
 
1908
and rationale.</p>
 
1909
</div>
 
1910
</li>
 
1911
<li><strong>version_id_generator</strong> &#8211; <p>Define how new version ids should
 
1912
be generated.  Defaults to <tt class="docutils literal"><span class="pre">None</span></tt>, which indicates that
 
1913
a simple integer counting scheme be employed.  To provide a custom
 
1914
versioning scheme, provide a callable function of the form:</p>
 
1915
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">generate_version</span><span class="p">(</span><span class="n">version</span><span class="p">):</span>
 
1916
    <span class="k">return</span> <span class="n">next_version</span></pre></div>
 
1917
</div>
 
1918
<div class="admonition seealso">
 
1919
<p class="first admonition-title">See also</p>
 
1920
<p class="last"><a class="reference internal" href="#custom-version-counter"><em>Custom Version Counters / Types</em></a></p>
 
1921
</div>
1785
1922
</li>
1786
1923
<li><strong>with_polymorphic</strong> &#8211; <p>A tuple in the form <tt class="docutils literal"><span class="pre">(&lt;classes&gt;,</span>
1787
1924
<span class="pre">&lt;selectable&gt;)</span></tt> indicating the default style of &#8220;polymorphic&#8221;
1792
1929
loaded immediately. The second tuple argument &lt;selectable&gt;
1793
1930
indicates a selectable that will be used to query for multiple
1794
1931
classes.</p>
1795
 
<p>See also:</p>
1796
 
<p><a class="reference internal" href="inheritance.html#concrete-inheritance"><em>Concrete Table Inheritance</em></a> - typically uses <tt class="docutils literal"><span class="pre">with_polymorphic</span></tt>
1797
 
to specify a UNION statement to select from.</p>
1798
 
<p><a class="reference internal" href="inheritance.html#with-polymorphic"><em>Basic Control of Which Tables are Queried</em></a> - usage example of the related
1799
 
<a class="reference internal" href="query.html#sqlalchemy.orm.query.Query.with_polymorphic" title="sqlalchemy.orm.query.Query.with_polymorphic"><tt class="xref py py-meth docutils literal"><span class="pre">Query.with_polymorphic()</span></tt></a> method</p>
 
1932
<div class="admonition seealso">
 
1933
<p class="first admonition-title">See also</p>
 
1934
<p class="last"><a class="reference internal" href="inheritance.html#with-polymorphic"><em>Basic Control of Which Tables are Queried</em></a></p>
 
1935
</div>
1800
1936
</li>
1801
1937
</ul>
1802
1938
</td>
1913
2049
<tbody valign="top">
1914
2050
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1915
2051
<li><strong>table_map</strong> &#8211; mapping of polymorphic identities to
1916
 
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects.</li>
 
2052
<a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects.</li>
1917
2053
<li><strong>typecolname</strong> &#8211; string name of a &#8220;discriminator&#8221; column, which will be
1918
2054
derived from the query, producing the polymorphic identity for
1919
2055
each row.  If <tt class="docutils literal"><span class="pre">None</span></tt>, no polymorphic discriminator is generated.</li>
1920
 
<li><strong>aliasname</strong> &#8211; name of the <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.alias" title="sqlalchemy.sql.expression.alias"><tt class="xref py py-func docutils literal"><span class="pre">alias()</span></tt></a>
 
2056
<li><strong>aliasname</strong> &#8211; name of the <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.alias" title="sqlalchemy.sql.expression.alias"><tt class="xref py py-func docutils literal"><span class="pre">alias()</span></tt></a>
1921
2057
construct generated.</li>
1922
2058
<li><strong>cast_nulls</strong> &#8211; if True, non-existent columns, which are represented
1923
2059
as labeled NULLs, will be passed into CAST.   This is a legacy behavior
1933
2069
<dl class="class">
1934
2070
<dt id="sqlalchemy.orm.mapper.Mapper">
1935
2071
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.mapper.</tt><tt class="descname">Mapper</tt><big>(</big><em>class_</em>, <em>local_table</em>, <em>properties=None</em>, <em>primary_key=None</em>, <em>non_primary=False</em>, <em>inherits=None</em>, <em>inherit_condition=None</em>, <em>inherit_foreign_keys=None</em>, <em>extension=None</em>, <em>order_by=False</em>, <em>always_refresh=False</em>, <em>version_id_col=None</em>, <em>version_id_generator=None</em>, <em>polymorphic_on=None</em>, <em>_polymorphic_map=None</em>, <em>polymorphic_identity=None</em>, <em>concrete=False</em>, <em>with_polymorphic=None</em>, <em>allow_partial_pks=True</em>, <em>batch=True</em>, <em>column_prefix=None</em>, <em>include_properties=None</em>, <em>exclude_properties=None</em>, <em>passive_updates=True</em>, <em>eager_defaults=False</em>, <em>legacy_is_orphan=False</em>, <em>_compiled_cache_size=100</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper" title="Permalink to this definition">¶</a></dt>
1936
 
<dd><p>Define the correlation of class attributes to database table
 
2072
<dd><p>Bases: <a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces._InspectionAttr" title="sqlalchemy.orm.interfaces._InspectionAttr"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.orm.interfaces._InspectionAttr</span></tt></a></p>
 
2073
<p>Define the correlation of class attributes to database table
1937
2074
columns.</p>
1938
2075
<p>The <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> object is instantiated using the
1939
2076
<a class="reference internal" href="#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a> function.    For information
2001
2138
<a class="reference internal" href="internals.html#sqlalchemy.orm.attributes.QueryableAttribute.property" title="sqlalchemy.orm.attributes.QueryableAttribute.property"><tt class="xref py py-attr docutils literal"><span class="pre">QueryableAttribute.property</span></tt></a> attribute refers to the
2002
2139
<a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces.MapperProperty" title="sqlalchemy.orm.interfaces.MapperProperty"><tt class="xref py py-class docutils literal"><span class="pre">MapperProperty</span></tt></a> property, which is what you get when referring
2003
2140
to the collection of mapped properties via <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.attrs" title="sqlalchemy.orm.mapper.Mapper.attrs"><tt class="xref py py-attr docutils literal"><span class="pre">Mapper.attrs</span></tt></a>.</p>
2004
 
<p class="versionadded">
2005
 
<span class="versionmodified">New in version 0.8.0.</span></p>
2006
 
<div class="admonition-see-also admonition seealso">
 
2141
<div class="versionadded">
 
2142
<p><span>New in version 0.8.0.</span></p>
 
2143
</div>
 
2144
<div class="admonition seealso">
2007
2145
<p class="first admonition-title">See also</p>
2008
2146
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.attrs" title="sqlalchemy.orm.mapper.Mapper.attrs"><tt class="xref py py-attr docutils literal"><span class="pre">Mapper.attrs</span></tt></a></p>
2009
2147
</div>
2025
2163
of this attribute which limit the types of properties
2026
2164
returned, inclding <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.synonyms" title="sqlalchemy.orm.mapper.Mapper.synonyms"><tt class="xref py py-attr docutils literal"><span class="pre">synonyms</span></tt></a>, <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.column_attrs" title="sqlalchemy.orm.mapper.Mapper.column_attrs"><tt class="xref py py-attr docutils literal"><span class="pre">column_attrs</span></tt></a>,
2027
2165
<a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.relationships" title="sqlalchemy.orm.mapper.Mapper.relationships"><tt class="xref py py-attr docutils literal"><span class="pre">relationships</span></tt></a>, and <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.composites" title="sqlalchemy.orm.mapper.Mapper.composites"><tt class="xref py py-attr docutils literal"><span class="pre">composites</span></tt></a>.</p>
2028
 
<div class="admonition-see-also admonition seealso">
 
2166
<div class="admonition seealso">
2029
2167
<p class="first admonition-title">See also</p>
2030
2168
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.all_orm_descriptors" title="sqlalchemy.orm.mapper.Mapper.all_orm_descriptors"><tt class="xref py py-attr docutils literal"><span class="pre">Mapper.all_orm_descriptors</span></tt></a></p>
2031
2169
</div>
2102
2240
<dl class="attribute">
2103
2241
<dt id="sqlalchemy.orm.mapper.Mapper.columns">
2104
2242
<tt class="descname">columns</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.columns" title="Permalink to this definition">¶</a></dt>
2105
 
<dd><p>A collection of <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> or other scalar expression
 
2243
<dd><p>A collection of <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> or other scalar expression
2106
2244
objects maintained by this <a class="reference internal" href="#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>
2107
2245
<p>The collection behaves the same as that of the <tt class="docutils literal"><span class="pre">c</span></tt> attribute on
2108
 
any <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object, except that only those columns included in
 
2246
any <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object, except that only those columns included in
2109
2247
this mapping are present, and are keyed based on the attribute name
2110
2248
defined in the mapping, not necessarily the <tt class="docutils literal"><span class="pre">key</span></tt> attribute of the
2111
 
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> itself.   Additionally, scalar expressions mapped
 
2249
<a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> itself.   Additionally, scalar expressions mapped
2112
2250
by <a class="reference internal" href="#sqlalchemy.orm.column_property" title="sqlalchemy.orm.column_property"><tt class="xref py py-func docutils literal"><span class="pre">column_property()</span></tt></a> are also present here.</p>
2113
2251
<p>This is a <em>read only</em> attribute determined during mapper construction.
2114
2252
Behavior is undefined if directly modified.</p>
2125
2263
<dt id="sqlalchemy.orm.mapper.Mapper.compile">
2126
2264
<tt class="descname">compile</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.compile" title="Permalink to this definition">¶</a></dt>
2127
2265
<dd><p>Initialize the inter-mapper relationships of all mappers that</p>
2128
 
<p class="deprecated">
2129
 
<span class="versionmodified">Deprecated since version 0.7: </span><a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.compile" title="sqlalchemy.orm.mapper.Mapper.compile"><tt class="xref py py-meth docutils literal"><span class="pre">Mapper.compile()</span></tt></a> is replaced by <a class="reference internal" href="#sqlalchemy.orm.configure_mappers" title="sqlalchemy.orm.configure_mappers"><tt class="xref py py-func docutils literal"><span class="pre">configure_mappers()</span></tt></a></p>
 
2266
<div class="deprecated">
 
2267
<p><span>Deprecated since version 0.7: </span><a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.compile" title="sqlalchemy.orm.mapper.Mapper.compile"><tt class="xref py py-meth docutils literal"><span class="pre">Mapper.compile()</span></tt></a> is replaced by <a class="reference internal" href="#sqlalchemy.orm.configure_mappers" title="sqlalchemy.orm.configure_mappers"><tt class="xref py py-func docutils literal"><span class="pre">configure_mappers()</span></tt></a></p>
 
2268
</div>
2130
2269
<p>have been constructed thus far.</p>
2131
2270
</dd></dl>
2132
2271
 
2133
2272
<dl class="attribute">
2134
2273
<dt id="sqlalchemy.orm.mapper.Mapper.compiled">
2135
2274
<tt class="descname">compiled</tt><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.compiled" title="Permalink to this definition">¶</a></dt>
2136
 
<dd><p class="deprecated">
2137
 
<span class="versionmodified">Deprecated since version 0.7: </span><a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.compiled" title="sqlalchemy.orm.mapper.Mapper.compiled"><tt class="xref py py-attr docutils literal"><span class="pre">Mapper.compiled</span></tt></a> is replaced by <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.configured" title="sqlalchemy.orm.mapper.Mapper.configured"><tt class="xref py py-attr docutils literal"><span class="pre">Mapper.configured</span></tt></a></p>
 
2275
<dd><div class="deprecated">
 
2276
<p><span>Deprecated since version 0.7: </span><a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.compiled" title="sqlalchemy.orm.mapper.Mapper.compiled"><tt class="xref py py-attr docutils literal"><span class="pre">Mapper.compiled</span></tt></a> is replaced by <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.configured" title="sqlalchemy.orm.mapper.Mapper.configured"><tt class="xref py py-attr docutils literal"><span class="pre">Mapper.configured</span></tt></a></p>
 
2277
</div>
2138
2278
</dd></dl>
2139
2279
 
2140
2280
<dl class="attribute">
2181
2321
<dl class="method">
2182
2322
<dt id="sqlalchemy.orm.mapper.Mapper.get_property_by_column">
2183
2323
<tt class="descname">get_property_by_column</tt><big>(</big><em>column</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.get_property_by_column" title="Permalink to this definition">¶</a></dt>
2184
 
<dd><p>Given a <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object, return the
 
2324
<dd><p>Given a <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> object, return the
2185
2325
<a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces.MapperProperty" title="sqlalchemy.orm.interfaces.MapperProperty"><tt class="xref py py-class docutils literal"><span class="pre">MapperProperty</span></tt></a> which maps this column.</p>
2186
2326
</dd></dl>
2187
2327
 
2248
2388
<dl class="attribute">
2249
2389
<dt id="sqlalchemy.orm.mapper.Mapper.local_table">
2250
2390
<tt class="descname">local_table</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.local_table" title="Permalink to this definition">¶</a></dt>
2251
 
<dd><p>The <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a> which this <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> manages.</p>
2252
 
<p>Typically is an instance of <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> or <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a>.
 
2391
<dd><p>The <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a> which this <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> manages.</p>
 
2392
<p>Typically is an instance of <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> or <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a>.
2253
2393
May also be <tt class="docutils literal"><span class="pre">None</span></tt>.</p>
2254
2394
<p>The &#8220;local&#8221; table is the
2255
2395
selectable that the <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> is directly responsible for
2265
2405
<dl class="attribute">
2266
2406
<dt id="sqlalchemy.orm.mapper.Mapper.mapped_table">
2267
2407
<tt class="descname">mapped_table</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.mapped_table" title="Permalink to this definition">¶</a></dt>
2268
 
<dd><p>The <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a> to which this <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> is mapped.</p>
2269
 
<p>Typically an instance of <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>, or
2270
 
<a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a>.</p>
 
2408
<dd><p>The <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a> to which this <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> is mapped.</p>
 
2409
<p>Typically an instance of <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>, or
 
2410
<a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a>.</p>
2271
2411
<p>The &#8220;mapped&#8221; table is the selectable that
2272
2412
the mapper selects from during queries.   For non-inheriting
2273
2413
mappers, the mapped table is the same as the &#8220;local&#8221; table.
2274
2414
For joined-table inheritance mappers, mapped_table references the
2275
 
full <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> representing full rows for this particular
 
2415
full <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> representing full rows for this particular
2276
2416
subclass.  For single-table inheritance mappers, mapped_table
2277
2417
references the base table.</p>
2278
2418
<p>See also <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.local_table" title="sqlalchemy.orm.mapper.Mapper.local_table"><tt class="xref py py-attr docutils literal"><span class="pre">local_table</span></tt></a>.</p>
2335
2475
<dl class="attribute">
2336
2476
<dt id="sqlalchemy.orm.mapper.Mapper.polymorphic_on">
2337
2477
<tt class="descname">polymorphic_on</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.polymorphic_on" title="Permalink to this definition">¶</a></dt>
2338
 
<dd><p>The <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> or SQL expression specified as the
 
2478
<dd><p>The <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> or SQL expression specified as the
2339
2479
<tt class="docutils literal"><span class="pre">polymorphic_on</span></tt> argument
2340
2480
for this <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a>, within an inheritance scenario.</p>
2341
 
<p>This attribute is normally a <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> instance but
 
2481
<p>This attribute is normally a <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> instance but
2342
2482
may also be an expression, such as one derived from
2343
 
<a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.cast" title="sqlalchemy.sql.expression.cast"><tt class="xref py py-func docutils literal"><span class="pre">cast()</span></tt></a>.</p>
 
2483
<a class="reference internal" href="../core/sqlelement.html#sqlalchemy.sql.expression.cast" title="sqlalchemy.sql.expression.cast"><tt class="xref py py-func docutils literal"><span class="pre">cast()</span></tt></a>.</p>
2344
2484
<p>This is a <em>read only</em> attribute determined during mapper construction.
2345
2485
Behavior is undefined if directly modified.</p>
2346
2486
</dd></dl>
2348
2488
<dl class="attribute">
2349
2489
<dt id="sqlalchemy.orm.mapper.Mapper.primary_key">
2350
2490
<tt class="descname">primary_key</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.primary_key" title="Permalink to this definition">¶</a></dt>
2351
 
<dd><p>An iterable containing the collection of <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects
 
2491
<dd><p>An iterable containing the collection of <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects
2352
2492
which comprise the &#8216;primary key&#8217; of the mapped table, from the
2353
2493
perspective of this <a class="reference internal" href="#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>
2354
2494
<p>This list is against the selectable in <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.mapped_table" title="sqlalchemy.orm.mapper.Mapper.mapped_table"><tt class="xref py py-attr docutils literal"><span class="pre">mapped_table</span></tt></a>. In
2355
2495
the case of inheriting mappers, some columns may be managed by a
2356
 
superclass mapper.  For example, in the case of a <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>, the
 
2496
superclass mapper.  For example, in the case of a <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>, the
2357
2497
primary key is determined by all of the primary key columns across all
2358
 
tables referenced by the <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>.</p>
 
2498
tables referenced by the <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>.</p>
2359
2499
<p>The list is also not necessarily the same as the primary key column
2360
2500
collection associated with the underlying tables; the <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a>
2361
2501
features a <tt class="docutils literal"><span class="pre">primary_key</span></tt> argument that can override what the
2391
2531
<dl class="attribute">
2392
2532
<dt id="sqlalchemy.orm.mapper.Mapper.selectable">
2393
2533
<tt class="descname">selectable</tt><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.selectable" title="Permalink to this definition">¶</a></dt>
2394
 
<dd><p>The <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct this <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> selects from
 
2534
<dd><p>The <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct this <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> selects from
2395
2535
by default.</p>
2396
2536
<p>Normally, this is equivalent to <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper.mapped_table" title="sqlalchemy.orm.mapper.Mapper.mapped_table"><tt class="xref py py-attr docutils literal"><span class="pre">mapped_table</span></tt></a>, unless
2397
2537
the <tt class="docutils literal"><span class="pre">with_polymorphic</span></tt> feature is in use, in which case the
2398
 
full &#8220;polymoprhic&#8221; selectable is returned.</p>
 
2538
full &#8220;polymorphic&#8221; selectable is returned.</p>
2399
2539
</dd></dl>
2400
2540
 
2401
2541
<dl class="attribute">
2429
2569
<dl class="attribute">
2430
2570
<dt id="sqlalchemy.orm.mapper.Mapper.tables">
2431
2571
<tt class="descname">tables</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.orm.mapper.Mapper.tables" title="Permalink to this definition">¶</a></dt>
2432
 
<dd><p>An iterable containing the collection of <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects
 
2572
<dd><p>An iterable containing the collection of <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects
2433
2573
which this <a class="reference internal" href="#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> is aware of.</p>
2434
 
<p>If the mapper is mapped to a <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>, or an <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a>
2435
 
representing a <a class="reference internal" href="../core/expression_api.html#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>, the individual <a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
 
2574
<p>If the mapper is mapped to a <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>, or an <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a>
 
2575
representing a <a class="reference internal" href="../core/selectable.html#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>, the individual <a class="reference internal" href="../core/metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
2436
2576
objects that comprise the full construct will be represented here.</p>
2437
2577
<p>This is a <em>read only</em> attribute determined during mapper construction.
2438
2578
Behavior is undefined if directly modified.</p>
2471
2611
 
2472
2612
    <div id="docs-copyright">
2473
2613
        &copy; <a href="../copyright.html">Copyright</a> 2007-2013, the SQLAlchemy authors and contributors.
2474
 
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
 
2614
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2b1.
2475
2615
    </div>
2476
2616
</div>
2477
2617