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

« back to all changes in this revision

Viewing changes to doc/orm/inheritance.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>
385
385
<div class="highlight-python"><div class="highlight"><pre><span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">Employee</span><span class="p">)</span><span class="o">.</span><span class="n">with_polymorphic</span><span class="p">([</span><span class="n">Engineer</span><span class="p">,</span> <span class="n">Manager</span><span class="p">])</span><span class="o">.</span>\
386
386
    <span class="nb">filter</span><span class="p">(</span><span class="n">or_</span><span class="p">(</span><span class="n">Engineer</span><span class="o">.</span><span class="n">engineer_info</span><span class="o">==</span><span class="s">&#39;w&#39;</span><span class="p">,</span> <span class="n">Manager</span><span class="o">.</span><span class="n">manager_data</span><span class="o">==</span><span class="s">&#39;q&#39;</span><span class="p">))</span></pre></div>
387
387
</div>
388
 
<p class="versionadded">
389
 
<span class="versionmodified">New in version 0.8: </span><a class="reference internal" href="#sqlalchemy.orm.with_polymorphic" title="sqlalchemy.orm.with_polymorphic"><tt class="xref py py-func docutils literal"><span class="pre">orm.with_polymorphic()</span></tt></a>, an improved version of
 
388
<div class="versionadded">
 
389
<p><span>New in version 0.8: </span><a class="reference internal" href="#sqlalchemy.orm.with_polymorphic" title="sqlalchemy.orm.with_polymorphic"><tt class="xref py py-func docutils literal"><span class="pre">orm.with_polymorphic()</span></tt></a>, an improved version of
390
390
<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>
 
391
</div>
391
392
<p>The mapper also accepts <tt class="docutils literal"><span class="pre">with_polymorphic</span></tt> as a configurational argument so
392
393
that the joined-style load will be issued automatically. This argument may be
393
394
the string <tt class="docutils literal"><span class="pre">'*'</span></tt>, a list of classes, or a tuple consisting of either,
422
423
<tt class="descclassname">sqlalchemy.orm.</tt><tt class="descname">with_polymorphic</tt><big>(</big><em>base</em>, <em>classes</em>, <em>selectable=False</em>, <em>polymorphic_on=None</em>, <em>aliased=False</em>, <em>innerjoin=False</em>, <em>_use_mapper_path=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.with_polymorphic" title="Permalink to this definition">¶</a></dt>
423
424
<dd><p>Produce an <a class="reference internal" href="query.html#sqlalchemy.orm.util.AliasedClass" title="sqlalchemy.orm.util.AliasedClass"><tt class="xref py py-class docutils literal"><span class="pre">AliasedClass</span></tt></a> construct which specifies
424
425
columns for descendant mappers of the given base.</p>
425
 
<p class="versionadded">
426
 
<span class="versionmodified">New in version 0.8: </span><a class="reference internal" href="#sqlalchemy.orm.with_polymorphic" title="sqlalchemy.orm.with_polymorphic"><tt class="xref py py-func docutils literal"><span class="pre">orm.with_polymorphic()</span></tt></a> is in addition to the existing
 
426
<div class="versionadded">
 
427
<p><span>New in version 0.8: </span><a class="reference internal" href="#sqlalchemy.orm.with_polymorphic" title="sqlalchemy.orm.with_polymorphic"><tt class="xref py py-func docutils literal"><span class="pre">orm.with_polymorphic()</span></tt></a> is in addition to the existing
427
428
<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> method <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>,
428
429
which has the same purpose but is not as flexible in its usage.</p>
 
430
</div>
429
431
<p>Using this method will ensure that each descendant mapper&#8217;s
430
432
tables are included in the FROM clause, and will allow filter()
431
433
criterion to be used against those tables.  The resulting
478
480
simplistic scenarios.   However, direct control of table rendering
479
481
is called for, such as the case when one wants to
480
482
render to only the subclass table and not the parent table.</p>
481
 
<p>This use case can be achieved by using 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>
 
483
<p>This use case can be achieved by using 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>
482
484
objects directly.   For example, to
483
485
query the name of employees with particular criterion:</p>
484
486
<div class="highlight-python"><div class="highlight"><pre><span class="n">engineer</span> <span class="o">=</span> <span class="n">Engineer</span><span class="o">.</span><span class="n">__table__</span>
620
622
<p>The EXISTS subquery above selects from the join of <tt class="docutils literal"><span class="pre">employees</span></tt> to
621
623
<tt class="docutils literal"><span class="pre">engineers</span></tt>, and also specifies criterion which correlates the EXISTS
622
624
subselect back to the parent <tt class="docutils literal"><span class="pre">companies</span></tt> table.</p>
623
 
<p class="versionadded">
624
 
<span class="versionmodified">New in version 0.8: </span><a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces.PropComparator.of_type" title="sqlalchemy.orm.interfaces.PropComparator.of_type"><tt class="xref py py-func docutils literal"><span class="pre">of_type()</span></tt></a> accepts
 
625
<div class="versionadded">
 
626
<p><span>New in version 0.8: </span><a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces.PropComparator.of_type" title="sqlalchemy.orm.interfaces.PropComparator.of_type"><tt class="xref py py-func docutils literal"><span class="pre">of_type()</span></tt></a> accepts
625
627
<a class="reference internal" href="query.html#sqlalchemy.orm.aliased" title="sqlalchemy.orm.aliased"><tt class="xref py py-func docutils literal"><span class="pre">orm.aliased()</span></tt></a> and <a class="reference internal" href="#sqlalchemy.orm.with_polymorphic" title="sqlalchemy.orm.with_polymorphic"><tt class="xref py py-func docutils literal"><span class="pre">orm.with_polymorphic()</span></tt></a> constructs in conjunction
626
628
with <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query.join" title="sqlalchemy.orm.query.Query.join"><tt class="xref py py-meth docutils literal"><span class="pre">Query.join()</span></tt></a>, <tt class="docutils literal"><span class="pre">any()</span></tt> and <tt class="docutils literal"><span class="pre">has()</span></tt>.</p>
627
629
</div>
 
630
</div>
628
631
<div class="section" id="eager-loading-of-specific-subtypes">
629
632
<h3>Eager Loading of Specific Subtypes<a class="headerlink" href="#eager-loading-of-specific-subtypes" title="Permalink to this headline">¶</a></h3>
630
633
<p>The <a class="reference internal" href="loading.html#sqlalchemy.orm.joinedload" title="sqlalchemy.orm.joinedload"><tt class="xref py py-func docutils literal"><span class="pre">joinedload()</span></tt></a> and <a class="reference internal" href="loading.html#sqlalchemy.orm.subqueryload" title="sqlalchemy.orm.subqueryload"><tt class="xref py py-func docutils literal"><span class="pre">subqueryload()</span></tt></a> options also support
635
638
    <span class="n">options</span><span class="p">(</span><span class="n">subqueryload_all</span><span class="p">(</span><span class="n">Company</span><span class="o">.</span><span class="n">employees</span><span class="o">.</span><span class="n">of_type</span><span class="p">(</span><span class="n">Engineer</span><span class="p">),</span>
636
639
                    <span class="n">Engineer</span><span class="o">.</span><span class="n">machines</span><span class="p">))</span></pre></div>
637
640
</div>
638
 
<p class="versionadded">
639
 
<span class="versionmodified">New in version 0.8: </span><a class="reference internal" href="loading.html#sqlalchemy.orm.joinedload" title="sqlalchemy.orm.joinedload"><tt class="xref py py-func docutils literal"><span class="pre">joinedload()</span></tt></a> and <a class="reference internal" href="loading.html#sqlalchemy.orm.subqueryload" title="sqlalchemy.orm.subqueryload"><tt class="xref py py-func docutils literal"><span class="pre">subqueryload()</span></tt></a> support
 
641
<div class="versionadded">
 
642
<p><span>New in version 0.8: </span><a class="reference internal" href="loading.html#sqlalchemy.orm.joinedload" title="sqlalchemy.orm.joinedload"><tt class="xref py py-func docutils literal"><span class="pre">joinedload()</span></tt></a> and <a class="reference internal" href="loading.html#sqlalchemy.orm.subqueryload" title="sqlalchemy.orm.subqueryload"><tt class="xref py py-func docutils literal"><span class="pre">subqueryload()</span></tt></a> support
640
643
paths that are qualified with
641
644
<a class="reference internal" href="internals.html#sqlalchemy.orm.interfaces.PropComparator.of_type" title="sqlalchemy.orm.interfaces.PropComparator.of_type"><tt class="xref py py-func docutils literal"><span class="pre">of_type()</span></tt></a>.</p>
642
645
</div>
643
646
</div>
 
647
</div>
644
648
<div class="section" id="single-table-inheritance">
645
649
<h2>Single Table Inheritance<a class="headerlink" href="#single-table-inheritance" title="Permalink to this headline">¶</a></h2>
646
650
<p>Single table inheritance is where the attributes of the base class as well as
765
769
</div>
766
770
<div class="section" id="concrete-inheritance-with-declarative">
767
771
<h3>Concrete Inheritance with Declarative<a class="headerlink" href="#concrete-inheritance-with-declarative" title="Permalink to this headline">¶</a></h3>
768
 
<p class="versionadded">
769
 
<span class="versionmodified">New in version 0.7.3: </span>The <a class="reference internal" href="extensions/declarative.html"><em>Declarative</em></a> module includes helpers for concrete
 
772
<div class="versionadded">
 
773
<p><span>New in version 0.7.3: </span>The <a class="reference internal" href="extensions/declarative.html"><em>Declarative</em></a> module includes helpers for concrete
770
774
inheritance. See <a class="reference internal" href="extensions/declarative.html#declarative-concrete-helpers"><em>Using the Concrete Helpers</em></a> for more information.</p>
771
775
</div>
772
776
</div>
 
777
</div>
773
778
<div class="section" id="using-relationships-with-inheritance">
774
779
<h2>Using Relationships with Inheritance<a class="headerlink" href="#using-relationships-with-inheritance" title="Permalink to this headline">¶</a></h2>
775
780
<p>Both joined-table and single table inheritance scenarios produce mappings
896
901
 
897
902
    <div id="docs-copyright">
898
903
        &copy; <a href="../copyright.html">Copyright</a> 2007-2013, the SQLAlchemy authors and contributors.
899
 
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
 
904
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2b1.
900
905
    </div>
901
906
</div>
902
907