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

« back to all changes in this revision

Viewing changes to doc/changelog/migration_05.html

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
 
 
4
<html xmlns="http://www.w3.org/1999/xhtml">
 
5
    <head>
 
6
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
7
        
 
8
        <title>
 
9
            
 
10
    
 
11
                What&#8217;s new in SQLAlchemy 0.5?
 
12
             &mdash; 
 
13
    SQLAlchemy 0.8 Documentation
 
14
 
 
15
        </title>
 
16
        
 
17
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
 
18
    <link rel="stylesheet" href="../_static/docs.css" type="text/css" />
 
19
 
 
20
    <script type="text/javascript">
 
21
      var DOCUMENTATION_OPTIONS = {
 
22
          URL_ROOT:    '../',
 
23
          VERSION:     '0.8.2',
 
24
          COLLAPSE_MODINDEX: false,
 
25
          FILE_SUFFIX: '.html'
 
26
      };
 
27
    </script>
 
28
        <script type="text/javascript" src="../_static/jquery.js"></script>
 
29
        <script type="text/javascript" src="../_static/underscore.js"></script>
 
30
        <script type="text/javascript" src="../_static/doctools.js"></script>
 
31
    <script type="text/javascript" src="../_static/init.js"></script>
 
32
    <link rel="index" title="Index" href="../genindex.html" />
 
33
    <link rel="search" title="Search" href="../search.html" />
 
34
        <link rel="copyright" title="Copyright" href="../copyright.html" />
 
35
    <link rel="top" title="SQLAlchemy 0.8 Documentation" href="../index.html" />
 
36
        <link rel="up" title="Changes and Migration" href="index.html" />
 
37
        <link rel="next" title="What&#8217;s new in SQLAlchemy 0.4?" href="migration_04.html" />
 
38
        <link rel="prev" title="What&#8217;s New in SQLAlchemy 0.6?" href="migration_06.html" />
 
39
 
 
40
    </head>
 
41
    <body>
 
42
        
 
43
 
 
44
 
 
45
 
 
46
 
 
47
 
 
48
 
 
49
 
 
50
 
 
51
 
 
52
 
 
53
<div id="docs-container">
 
54
 
 
55
 
 
56
 
 
57
<div id="docs-header">
 
58
    <h1>SQLAlchemy 0.8 Documentation</h1>
 
59
 
 
60
    <div id="docs-search">
 
61
    Search:
 
62
    <form class="search" action="../search.html" method="get">
 
63
      <input type="text" name="q" size="18" /> <input type="submit" value="Search" />
 
64
      <input type="hidden" name="check_keywords" value="yes" />
 
65
      <input type="hidden" name="area" value="default" />
 
66
    </form>
 
67
    </div>
 
68
 
 
69
    <div id="docs-version-header">
 
70
        Release: <span class="version-num">0.8.2</span> | Release Date: July 3, 2013
 
71
 
 
72
 
 
73
    </div>
 
74
 
 
75
</div>
 
76
 
 
77
<div id="docs-top-navigation">
 
78
    <div id="docs-top-page-control" class="docs-navigation-links">
 
79
        <ul>
 
80
            <li>Prev:
 
81
            <a href="migration_06.html" title="previous chapter">What&#8217;s New in SQLAlchemy 0.6?</a>
 
82
            </li>
 
83
            <li>Next:
 
84
            <a href="migration_04.html" title="next chapter">What&#8217;s new in SQLAlchemy 0.4?</a>
 
85
            </li>
 
86
 
 
87
        <li>
 
88
            <a href="../contents.html">Table of Contents</a> |
 
89
            <a href="../genindex.html">Index</a>
 
90
            | <a href="../_sources/changelog/migration_05.txt">view source
 
91
        </li>
 
92
        </ul>
 
93
    </div>
 
94
 
 
95
    <div id="docs-navigation-banner">
 
96
        <a href="../index.html">SQLAlchemy 0.8 Documentation</a>
 
97
                » <a href="index.html" title="Changes and Migration">Changes and Migration</a>
 
98
        » 
 
99
                What&#8217;s new in SQLAlchemy 0.5?
 
100
             
 
101
 
 
102
        <h2>
 
103
            
 
104
                What&#8217;s new in SQLAlchemy 0.5?
 
105
            
 
106
        </h2>
 
107
    </div>
 
108
 
 
109
</div>
 
110
 
 
111
<div id="docs-body-container">
 
112
 
 
113
    <div id="docs-sidebar">
 
114
    <h3><a href="../index.html">Table of Contents</a></h3>
 
115
    <ul>
 
116
<li><a class="reference internal" href="#">What&#8217;s new in SQLAlchemy 0.5?</a><ul>
 
117
<li><a class="reference internal" href="#major-documentation-changes">Major Documentation Changes</a></li>
 
118
<li><a class="reference internal" href="#deprecations-source">Deprecations Source</a></li>
 
119
<li><a class="reference internal" href="#requirements-changes">Requirements Changes</a></li>
 
120
<li><a class="reference internal" href="#object-relational-mapping">Object Relational Mapping</a></li>
 
121
<li><a class="reference internal" href="#extending-the-orm">Extending the ORM</a></li>
 
122
<li><a class="reference internal" href="#schema-types">Schema/Types</a></li>
 
123
<li><a class="reference internal" href="#connection-pool-no-longer-threadlocal-by-default">Connection Pool no longer threadlocal by default</a></li>
 
124
<li><a class="reference internal" href="#args-accepted-args-no-longer-accepted">*args Accepted, *args No Longer Accepted</a></li>
 
125
<li><a class="reference internal" href="#removed">Removed</a></li>
 
126
<li><a class="reference internal" href="#renamed-or-moved">Renamed or Moved</a></li>
 
127
<li><a class="reference internal" href="#deprecated">Deprecated</a></li>
 
128
</ul>
 
129
</li>
 
130
</ul>
 
131
 
 
132
 
 
133
    <h4>Previous Topic</h4>
 
134
    <p>
 
135
    <a href="migration_06.html" title="previous chapter">What&#8217;s New in SQLAlchemy 0.6?</a>
 
136
    </p>
 
137
    <h4>Next Topic</h4>
 
138
    <p>
 
139
    <a href="migration_04.html" title="next chapter">What&#8217;s new in SQLAlchemy 0.4?</a>
 
140
    </p>
 
141
 
 
142
 
 
143
    <h4>Quick Search</h4>
 
144
    <p>
 
145
    <form class="search" action="../search.html" method="get">
 
146
      <input type="text" name="q" size="18" /> <input type="submit" value="Search" />
 
147
      <input type="hidden" name="check_keywords" value="yes" />
 
148
      <input type="hidden" name="area" value="default" />
 
149
    </form>
 
150
    </p>
 
151
 
 
152
    </div>
 
153
 
 
154
    <div id="docs-body" class="withsidebar" >
 
155
        
 
156
<div class="section" id="what-s-new-in-sqlalchemy-0-5">
 
157
<h1>What&#8217;s new in SQLAlchemy 0.5?<a class="headerlink" href="#what-s-new-in-sqlalchemy-0-5" title="Permalink to this headline">¶</a></h1>
 
158
<div class="admonition-about-this-document admonition">
 
159
<p class="first admonition-title">About this Document</p>
 
160
<p>This document describes changes between SQLAlchemy version 0.4,
 
161
last released October 12, 2008, and SQLAlchemy version 0.5,
 
162
last released January 16, 2010.</p>
 
163
<p class="last">Document date: August 4, 2009</p>
 
164
</div>
 
165
<p>This guide documents API changes which affect users
 
166
migrating their applications from the 0.4 series of
 
167
SQLAlchemy to 0.5.   It&#8217;s also recommended for those working
 
168
from  <a class="reference external" href="http://oreilly.com/catalog/9780596516147/">Essential SQLAlchemy</a>, which only
 
169
covers 0.4 and seems to even have some old 0.3isms in it.
 
170
Note that SQLAlchemy 0.5 removes many behaviors which were
 
171
deprecated throughout the span of the 0.4 series, and also
 
172
deprecates more behaviors specific to 0.4.</p>
 
173
<div class="section" id="major-documentation-changes">
 
174
<h2>Major Documentation Changes<a class="headerlink" href="#major-documentation-changes" title="Permalink to this headline">¶</a></h2>
 
175
<p>Some sections of the documentation have been completely
 
176
rewritten and can serve as an introduction to new ORM
 
177
features.  The <tt class="docutils literal"><span class="pre">Query</span></tt> and <tt class="docutils literal"><span class="pre">Session</span></tt> objects in
 
178
particular have some distinct differences in API and
 
179
behavior which fundamentally change many of the basic ways
 
180
things are done, particularly with regards to constructing
 
181
highly customized ORM queries and dealing with stale session
 
182
state, commits and rollbacks.</p>
 
183
<ul class="simple">
 
184
<li><a class="reference external" href="http://www.sqlalchemy.org/docs/05/ormtutorial.html">ORM Tutorial</a></li>
 
185
<li><a class="reference external" href="http://www.sqlalchemy.org/docs/05/session.html">Session Documentation</a></li>
 
186
</ul>
 
187
</div>
 
188
<div class="section" id="deprecations-source">
 
189
<h2>Deprecations Source<a class="headerlink" href="#deprecations-source" title="Permalink to this headline">¶</a></h2>
 
190
<p>Another source of information is documented within a series
 
191
of unit tests illustrating up to date usages of some common
 
192
<tt class="docutils literal"><span class="pre">Query</span></tt> patterns; this file can be viewed at
 
193
[source:sqlalchemy/trunk/test/orm/test_deprecations.py].</p>
 
194
</div>
 
195
<div class="section" id="requirements-changes">
 
196
<h2>Requirements Changes<a class="headerlink" href="#requirements-changes" title="Permalink to this headline">¶</a></h2>
 
197
<ul class="simple">
 
198
<li>Python 2.4 or higher is required.  The SQLAlchemy 0.4 line
 
199
is the last version with Python 2.3 support.</li>
 
200
</ul>
 
201
</div>
 
202
<div class="section" id="object-relational-mapping">
 
203
<h2>Object Relational Mapping<a class="headerlink" href="#object-relational-mapping" title="Permalink to this headline">¶</a></h2>
 
204
<ul>
 
205
<li><p class="first"><strong>Column level expressions within Query.</strong> - as detailed
 
206
in the <a class="reference external" href="http://www.sqlalchemy.org/docs/05/ormtutorial.html">tutorial</a>,
 
207
<tt class="docutils literal"><span class="pre">Query</span></tt> has the capability to create specific SELECT
 
208
statements, not just those against full rows:</p>
 
209
<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">User</span><span class="o">.</span><span class="n">name</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><span class="n">label</span><span class="p">(</span><span class="s">&quot;numaddresses&quot;</span><span class="p">))</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">Address</span><span class="p">)</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span><span class="n">User</span><span class="o">.</span><span class="n">name</span><span class="p">)</span></pre></div>
 
210
</div>
 
211
<p>The tuples returned by any multi-column/entity query are
 
212
<em>named</em>&#8216; tuples:</p>
 
213
<div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">User</span><span class="o">.</span><span class="n">name</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><span class="n">label</span><span class="p">(</span><span class="s">&#39;numaddresses&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">Address</span><span class="p">)</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span><span class="n">User</span><span class="o">.</span><span class="n">name</span><span class="p">):</span>
 
214
   <span class="k">print</span> <span class="s">&quot;name&quot;</span><span class="p">,</span> <span class="n">row</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">&quot;number&quot;</span><span class="p">,</span> <span class="n">row</span><span class="o">.</span><span class="n">numaddresses</span></pre></div>
 
215
</div>
 
216
<p><tt class="docutils literal"><span class="pre">Query</span></tt> has a <tt class="docutils literal"><span class="pre">statement</span></tt> accessor, as well as a
 
217
<tt class="docutils literal"><span class="pre">subquery()</span></tt> method which allow <tt class="docutils literal"><span class="pre">Query</span></tt> to be used to
 
218
create more complex combinations:</p>
 
219
<div class="highlight-python"><div class="highlight"><pre><span class="n">subq</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">Keyword</span><span class="o">.</span><span class="n">id</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&#39;keyword_id&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">Keyword</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">in_</span><span class="p">([</span><span class="s">&#39;beans&#39;</span><span class="p">,</span> <span class="s">&#39;carrots&#39;</span><span class="p">]))</span><span class="o">.</span><span class="n">subquery</span><span class="p">()</span>
 
220
<span class="n">recipes</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">Recipe</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">exists</span><span class="p">()</span><span class="o">.</span>
 
221
   <span class="n">where</span><span class="p">(</span><span class="n">Recipe</span><span class="o">.</span><span class="n">id</span><span class="o">==</span><span class="n">recipe_keywords</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">recipe_id</span><span class="p">)</span><span class="o">.</span>
 
222
   <span class="n">where</span><span class="p">(</span><span class="n">recipe_keywords</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">keyword_id</span><span class="o">==</span><span class="n">subq</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">keyword_id</span><span class="p">)</span>
 
223
<span class="p">)</span></pre></div>
 
224
</div>
 
225
</li>
 
226
<li><p class="first"><strong>Explicit ORM aliases are recommended for aliased joins</strong>
 
227
- The <tt class="docutils literal"><span class="pre">aliased()</span></tt> function produces an &#8220;alias&#8221; of a
 
228
class, which allows fine-grained control of aliases in
 
229
conjunction with ORM queries.  While a table-level alias
 
230
(i.e. <tt class="docutils literal"><span class="pre">table.alias()</span></tt>) is still usable, an ORM level
 
231
alias retains the semantics of the ORM mapped object which
 
232
is significant for inheritance mappings, options, and
 
233
other scenarios.  E.g.:</p>
 
234
<div class="highlight-python"><div class="highlight"><pre><span class="n">Friend</span> <span class="o">=</span> <span class="n">aliased</span><span class="p">(</span><span class="n">Person</span><span class="p">)</span>
 
235
<span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">Person</span><span class="p">,</span> <span class="n">Friend</span><span class="p">)</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">Friend</span><span class="p">,</span> <span class="n">Person</span><span class="o">.</span><span class="n">friends</span><span class="p">))</span><span class="o">.</span><span class="n">all</span><span class="p">()</span></pre></div>
 
236
</div>
 
237
</li>
 
238
<li><p class="first"><strong>query.join() greatly enhanced.</strong> - You can now specify
 
239
the target and ON clause for a join in multiple ways.   A
 
240
target class alone can be provided where SQLA will attempt
 
241
to form a join to it via foreign key in the same way as
 
242
<tt class="docutils literal"><span class="pre">table.join(someothertable)</span></tt>.  A target and an explicit
 
243
ON condition can be provided, where the ON condition can
 
244
be a <tt class="docutils literal"><span class="pre">relation()</span></tt> name, an actual class descriptor, or a
 
245
SQL expression.  Or the old way of just a <tt class="docutils literal"><span class="pre">relation()</span></tt>
 
246
name or class descriptor works too.   See the ORM tutorial
 
247
which has several examples.</p>
 
248
</li>
 
249
<li><p class="first"><strong>Declarative is recommended for applications which don&#8217;t
 
250
require (and don&#8217;t prefer) abstraction between tables and
 
251
mappers</strong> - The [/docs/05/reference/ext/declarative.html
 
252
Declarative] module, which is used to combine the
 
253
expression of <tt class="docutils literal"><span class="pre">Table</span></tt>, <tt class="docutils literal"><span class="pre">mapper()</span></tt>, and user defined
 
254
class objects together, is highly recommended as it
 
255
simplifies application configuration, ensures the &#8220;one
 
256
mapper per class&#8221; pattern, and allows the full range of
 
257
configuration available to distinct <tt class="docutils literal"><span class="pre">mapper()</span></tt> calls.
 
258
Separate <tt class="docutils literal"><span class="pre">mapper()</span></tt> and <tt class="docutils literal"><span class="pre">Table</span></tt> usage is now referred
 
259
to as &#8220;classical SQLAlchemy usage&#8221; and of course is freely
 
260
mixable with declarative.</p>
 
261
</li>
 
262
<li><p class="first"><strong>The .c. attribute has been removed</strong> from classes (i.e.
 
263
<tt class="docutils literal"><span class="pre">MyClass.c.somecolumn</span></tt>).  As is the case in 0.4, class-
 
264
level properties are usable as query elements, i.e.
 
265
<tt class="docutils literal"><span class="pre">Class.c.propname</span></tt> is now superseded by
 
266
<tt class="docutils literal"><span class="pre">Class.propname</span></tt>, and the <tt class="docutils literal"><span class="pre">c</span></tt> attribute continues to
 
267
remain on <tt class="docutils literal"><span class="pre">Table</span></tt> objects where they indicate the
 
268
namespace of <tt class="docutils literal"><span class="pre">Column</span></tt> objects present on the table.</p>
 
269
<p>To get at the Table for a mapped class (if you didn&#8217;t keep
 
270
it around already):</p>
 
271
<div class="highlight-python"><div class="highlight"><pre><span class="n">table</span> <span class="o">=</span> <span class="n">class_mapper</span><span class="p">(</span><span class="n">someclass</span><span class="p">)</span><span class="o">.</span><span class="n">mapped_table</span></pre></div>
 
272
</div>
 
273
<p>Iterate through columns:</p>
 
274
<div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="p">:</span>
 
275
    <span class="k">print</span> <span class="n">col</span></pre></div>
 
276
</div>
 
277
<p>Work with a specific column:</p>
 
278
<div class="highlight-python"><div class="highlight"><pre><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecolumn</span></pre></div>
 
279
</div>
 
280
<p>The class-bound descriptors support the full set of Column
 
281
operators as well as the documented relation-oriented
 
282
operators like <tt class="docutils literal"><span class="pre">has()</span></tt>, <tt class="docutils literal"><span class="pre">any()</span></tt>, <tt class="docutils literal"><span class="pre">contains()</span></tt>, etc.</p>
 
283
<p>The reason for the hard removal of <tt class="docutils literal"><span class="pre">.c.</span></tt> is that in 0.5,
 
284
class-bound descriptors carry potentially different
 
285
meaning, as well as information regarding class mappings,
 
286
versus plain <tt class="docutils literal"><span class="pre">Column</span></tt> objects - and there are use cases
 
287
where you&#8217;d specifically want to use one or the other.
 
288
Generally, using class-bound descriptors invokes a set of
 
289
mapping/polymorphic aware translations, and using table-
 
290
bound columns does not.  In 0.4, these translations were
 
291
applied across the board to all expressions, but 0.5
 
292
differentiates completely between columns and mapped
 
293
descriptors, only applying translations to the latter.  So
 
294
in many cases, particularly when dealing with joined table
 
295
inheritance configurations as well as when using
 
296
<tt class="docutils literal"><span class="pre">query(&lt;columns&gt;)</span></tt>, <tt class="docutils literal"><span class="pre">Class.propname</span></tt> and
 
297
<tt class="docutils literal"><span class="pre">table.c.colname</span></tt> are not interchangeable.</p>
 
298
<p>For example, <tt class="docutils literal"><span class="pre">session.query(users.c.id,</span> <span class="pre">users.c.name)</span></tt>
 
299
is different versus <tt class="docutils literal"><span class="pre">session.query(User.id,</span> <span class="pre">User.name)</span></tt>;
 
300
in the latter case, the <tt class="docutils literal"><span class="pre">Query</span></tt> is aware of the mapper
 
301
in use and further mapper-specific operations like
 
302
<tt class="docutils literal"><span class="pre">query.join(&lt;propname&gt;)</span></tt>, <tt class="docutils literal"><span class="pre">query.with_parent()</span></tt> etc.
 
303
may be used, but in the former case cannot.  Additionally,
 
304
in polymorphic inheritance scenarios, the class-bound
 
305
descriptors refer to the columns present in the
 
306
polymorphic selectable in use, not necessarily the table
 
307
column which directly corresponds to the descriptor.  For
 
308
example, a set of classes related by joined-table
 
309
inheritance to the <tt class="docutils literal"><span class="pre">person</span></tt> table along the
 
310
<tt class="docutils literal"><span class="pre">person_id</span></tt> column of each table will all have their
 
311
<tt class="docutils literal"><span class="pre">Class.person_id</span></tt> attribute mapped to the <tt class="docutils literal"><span class="pre">person_id</span></tt>
 
312
column in <tt class="docutils literal"><span class="pre">person</span></tt>, and not their subclass table.
 
313
Version 0.4 would map this behavior onto table-bound
 
314
<tt class="docutils literal"><span class="pre">Column</span></tt> objects automatically.  In 0.5, this automatic
 
315
conversion has been removed, so that you in fact <em>can</em> use
 
316
table-bound columns as a means to override the
 
317
translations which occur with polymorphic querying; this
 
318
allows <tt class="docutils literal"><span class="pre">Query</span></tt> to be able to create optimized selects
 
319
among joined-table or concrete-table inheritance setups,
 
320
as well as portable subqueries, etc.</p>
 
321
</li>
 
322
<li><p class="first"><strong>Session Now Synchronizes Automatically with
 
323
Transactions.</strong> Session now synchronizes against the
 
324
transaction automatically by default, including autoflush
 
325
and autoexpire.  A transaction is present at all times
 
326
unless disabled using the <tt class="docutils literal"><span class="pre">autocommit</span></tt> option.  When all
 
327
three flags are set to their default, the Session recovers
 
328
gracefully after rollbacks and it&#8217;s very difficult to get
 
329
stale data into the session.  See the new Session
 
330
documentation for details.</p>
 
331
</li>
 
332
<li><p class="first"><strong>Implicit Order By Is Removed</strong>.  This will impact ORM
 
333
users who rely upon SA&#8217;s &#8220;implicit ordering&#8221; behavior,
 
334
which states that all Query objects which don&#8217;t have an
 
335
<tt class="docutils literal"><span class="pre">order_by()</span></tt> will ORDER BY the &#8220;id&#8221; or &#8220;oid&#8221; column of
 
336
the primary mapped table, and all lazy/eagerly loaded
 
337
collections apply a similar ordering.   In 0.5, automatic
 
338
ordering must be explicitly configured on <tt class="docutils literal"><span class="pre">mapper()</span></tt> and
 
339
<tt class="docutils literal"><span class="pre">relation()</span></tt> objects (if desired), or otherwise when
 
340
using <tt class="docutils literal"><span class="pre">Query</span></tt>.</p>
 
341
<p>To convert an 0.4 mapping to 0.5, such that its ordering
 
342
behavior will be extremely similar to 0.4 or previous, use
 
343
the <tt class="docutils literal"><span class="pre">order_by</span></tt> setting on <tt class="docutils literal"><span class="pre">mapper()</span></tt> and
 
344
<tt class="docutils literal"><span class="pre">relation()</span></tt>:</p>
 
345
<div class="highlight-python"><div class="highlight"><pre><span class="n">mapper</span><span class="p">(</span><span class="n">User</span><span class="p">,</span> <span class="n">users</span><span class="p">,</span> <span class="n">properties</span><span class="o">=</span><span class="p">{</span>
 
346
    <span class="s">&#39;addresses&#39;</span><span class="p">:</span><span class="n">relation</span><span class="p">(</span><span class="n">Address</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="n">addresses</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
 
347
<span class="p">},</span> <span class="n">order_by</span><span class="o">=</span><span class="n">users</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">id</span><span class="p">)</span></pre></div>
 
348
</div>
 
349
<p>To set ordering on a backref, use the <tt class="docutils literal"><span class="pre">backref()</span></tt>
 
350
function:</p>
 
351
<div class="highlight-python"><pre>'keywords':relation(Keyword, secondary=item_keywords,
 
352
      order_by=keywords.c.name, backref=backref('items', order_by=items.c.id))</pre>
 
353
</div>
 
354
<p>Using declarative ?  To help with the new <tt class="docutils literal"><span class="pre">order_by</span></tt>
 
355
requirement, <tt class="docutils literal"><span class="pre">order_by</span></tt> and friends can now be set using
 
356
strings which are evaluated in Python later on (this works
 
357
<strong>only</strong> with declarative, not plain mappers):</p>
 
358
<div class="highlight-python"><pre>class MyClass(MyDeclarativeBase):
 
359
    ...
 
360
    'addresses':relation("Address", order_by="Address.id")</pre>
 
361
</div>
 
362
<p>It&#8217;s generally a good idea to set <tt class="docutils literal"><span class="pre">order_by</span></tt> on
 
363
<tt class="docutils literal"><span class="pre">relation()s</span></tt> which load list-based collections of
 
364
items, since that ordering cannot otherwise be affected.
 
365
Other than that, the best practice is to use
 
366
<tt class="docutils literal"><span class="pre">Query.order_by()</span></tt> to control ordering of the primary
 
367
entities being loaded.</p>
 
368
</li>
 
369
<li><p class="first"><strong>Session is now
 
370
autoflush=True/autoexpire=True/autocommit=False.</strong> - To
 
371
set it up, just call <tt class="docutils literal"><span class="pre">sessionmaker()</span></tt> with no arguments.
 
372
The name <tt class="docutils literal"><span class="pre">transactional=True</span></tt> is now
 
373
<tt class="docutils literal"><span class="pre">autocommit=False</span></tt>.  Flushes occur upon each query
 
374
issued (disable with <tt class="docutils literal"><span class="pre">autoflush=False</span></tt>), within each
 
375
<tt class="docutils literal"><span class="pre">commit()</span></tt> (as always), and before each
 
376
<tt class="docutils literal"><span class="pre">begin_nested()</span></tt> (so rolling back to the SAVEPOINT is
 
377
meaningful).   All objects are expired after each
 
378
<tt class="docutils literal"><span class="pre">commit()</span></tt> and after each <tt class="docutils literal"><span class="pre">rollback()</span></tt>.  After
 
379
rollback, pending objects are expunged, deleted objects
 
380
move back to persistent.  These defaults work together
 
381
very nicely and there&#8217;s really no more need for old
 
382
techniques like <tt class="docutils literal"><span class="pre">clear()</span></tt> (which is renamed to
 
383
<tt class="docutils literal"><span class="pre">expunge_all()</span></tt> as well).</p>
 
384
<p>P.S.:  sessions are now reusable after a <tt class="docutils literal"><span class="pre">rollback()</span></tt>.
 
385
Scalar and collection attribute changes, adds and deletes
 
386
are all rolled back.</p>
 
387
</li>
 
388
<li><p class="first"><strong>session.add() replaces session.save(), session.update(),
 
389
session.save_or_update().</strong> - the
 
390
<tt class="docutils literal"><span class="pre">session.add(someitem)</span></tt> and <tt class="docutils literal"><span class="pre">session.add_all([list</span> <span class="pre">of</span>
 
391
<span class="pre">items])</span></tt> methods replace <tt class="docutils literal"><span class="pre">save()</span></tt>, <tt class="docutils literal"><span class="pre">update()</span></tt>, and
 
392
<tt class="docutils literal"><span class="pre">save_or_update()</span></tt>.  Those methods will remain
 
393
deprecated throughout 0.5.</p>
 
394
</li>
 
395
<li><p class="first"><strong>backref configuration made less verbose.</strong> - The
 
396
<tt class="docutils literal"><span class="pre">backref()</span></tt> function now uses the <tt class="docutils literal"><span class="pre">primaryjoin</span></tt> and
 
397
<tt class="docutils literal"><span class="pre">secondaryjoin</span></tt> arguments of the forwards-facing
 
398
<tt class="docutils literal"><span class="pre">relation()</span></tt> when they are not explicitly stated.  It&#8217;s
 
399
no longer necessary to specify
 
400
<tt class="docutils literal"><span class="pre">primaryjoin</span></tt>/<tt class="docutils literal"><span class="pre">secondaryjoin</span></tt> in both directions
 
401
separately.</p>
 
402
</li>
 
403
<li><p class="first"><strong>Simplified polymorphic options.</strong> - The ORM&#8217;s
 
404
&#8220;polymorphic load&#8221; behavior has been simplified.  In 0.4,
 
405
mapper() had an argument called <tt class="docutils literal"><span class="pre">polymorphic_fetch</span></tt>
 
406
which could be configured as <tt class="docutils literal"><span class="pre">select</span></tt> or <tt class="docutils literal"><span class="pre">deferred</span></tt>.
 
407
This option is removed; the mapper will now just defer any
 
408
columns which were not present in the SELECT statement.
 
409
The actual SELECT statement used is controlled by the
 
410
<tt class="docutils literal"><span class="pre">with_polymorphic</span></tt> mapper argument (which is also in 0.4
 
411
and replaces <tt class="docutils literal"><span class="pre">select_table</span></tt>), as well as the
 
412
<tt class="docutils literal"><span class="pre">with_polymorphic()</span></tt> method on <tt class="docutils literal"><span class="pre">Query</span></tt> (also in 0.4).</p>
 
413
<p>An improvement to the deferred loading of inheriting
 
414
classes is that the mapper now produces the &#8220;optimized&#8221;
 
415
version of the SELECT statement in all cases; that is, if
 
416
class B inherits from A, and several attributes only
 
417
present on class B have been expired, the refresh
 
418
operation will only include B&#8217;s table in the SELECT
 
419
statement and will not JOIN to A.</p>
 
420
</li>
 
421
<li><p class="first">The <tt class="docutils literal"><span class="pre">execute()</span></tt> method on <tt class="docutils literal"><span class="pre">Session</span></tt> converts plain
 
422
strings into <tt class="docutils literal"><span class="pre">text()</span></tt> constructs, so that bind
 
423
parameters may all be specified as &#8221;:bindname&#8221; without
 
424
needing to call <tt class="docutils literal"><span class="pre">text()</span></tt> explicitly.  If &#8220;raw&#8221; SQL is
 
425
desired here, use <tt class="docutils literal"><span class="pre">session.connection().execute(&quot;raw</span>
 
426
<span class="pre">text&quot;)</span></tt>.</p>
 
427
</li>
 
428
<li><p class="first"><tt class="docutils literal"><span class="pre">session.Query().iterate_instances()</span></tt> has been renamed
 
429
to just <tt class="docutils literal"><span class="pre">instances()</span></tt>. The old <tt class="docutils literal"><span class="pre">instances()</span></tt> method
 
430
returning a list instead of an iterator no longer exists.
 
431
If you were relying on that behavior, you should use
 
432
<tt class="docutils literal"><span class="pre">list(your_query.instances())</span></tt>.</p>
 
433
</li>
 
434
</ul>
 
435
</div>
 
436
<div class="section" id="extending-the-orm">
 
437
<h2>Extending the ORM<a class="headerlink" href="#extending-the-orm" title="Permalink to this headline">¶</a></h2>
 
438
<p>In 0.5 we&#8217;re moving forward with more ways to modify and
 
439
extend the ORM.  Heres a summary:</p>
 
440
<ul class="simple">
 
441
<li><strong>MapperExtension.</strong> - This is the classic extension
 
442
class, which remains.   Methods which should rarely be
 
443
needed are <tt class="docutils literal"><span class="pre">create_instance()</span></tt> and
 
444
<tt class="docutils literal"><span class="pre">populate_instance()</span></tt>.  To control the initialization of
 
445
an object when it&#8217;s loaded from the database, use the
 
446
<tt class="docutils literal"><span class="pre">reconstruct_instance()</span></tt> method, or more easily the
 
447
<tt class="docutils literal"><span class="pre">&#64;reconstructor</span></tt> decorator described in the
 
448
documentation.</li>
 
449
<li><strong>SessionExtension.</strong> - This is an easy to use extension
 
450
class for session events.  In particular, it provides
 
451
<tt class="docutils literal"><span class="pre">before_flush()</span></tt>, <tt class="docutils literal"><span class="pre">after_flush()</span></tt> and
 
452
<tt class="docutils literal"><span class="pre">after_flush_postexec()</span></tt> methods.  It&#8217;s usage is
 
453
recommended over <tt class="docutils literal"><span class="pre">MapperExtension.before_XXX</span></tt> in many
 
454
cases since within <tt class="docutils literal"><span class="pre">before_flush()</span></tt> you can modify the
 
455
flush plan of the session freely, something which cannot
 
456
be done from within <tt class="docutils literal"><span class="pre">MapperExtension</span></tt>.</li>
 
457
<li><strong>AttributeExtension.</strong> - This class is now part of the
 
458
public API, and allows the interception of userland events
 
459
on attributes, including attribute set and delete
 
460
operations, and collection appends and removes.  It also
 
461
allows the value to be set or appended to be modified.
 
462
The <tt class="docutils literal"><span class="pre">&#64;validates</span></tt> decorator, described in the
 
463
documentation, provides a quick way to mark any mapped
 
464
attributes as being &#8220;validated&#8221; by a particular class
 
465
method.</li>
 
466
<li><strong>Attribute Instrumentation Customization.</strong> - An API is
 
467
provided for ambitious efforts to entirely replace
 
468
SQLAlchemy&#8217;s attribute instrumentation, or just to augment
 
469
it in some cases.  This API was produced for the purposes
 
470
of the Trellis toolkit, but is available as a public API.
 
471
Some examples are provided in the distribution in the
 
472
<tt class="docutils literal"><span class="pre">/examples/custom_attributes</span></tt> directory.</li>
 
473
</ul>
 
474
</div>
 
475
<div class="section" id="schema-types">
 
476
<h2>Schema/Types<a class="headerlink" href="#schema-types" title="Permalink to this headline">¶</a></h2>
 
477
<ul>
 
478
<li><p class="first"><strong>String with no length no longer generates TEXT, it
 
479
generates VARCHAR</strong> - The <tt class="docutils literal"><span class="pre">String</span></tt> type no longer
 
480
magically converts into a <tt class="docutils literal"><span class="pre">Text</span></tt> type when specified
 
481
with no length.  This only has an effect when CREATE TABLE
 
482
is issued, as it will issue <tt class="docutils literal"><span class="pre">VARCHAR</span></tt> with no length
 
483
parameter, which is not valid on many (but not all)
 
484
databases.  To create a TEXT (or CLOB, i.e. unbounded
 
485
string) column, use the <tt class="docutils literal"><span class="pre">Text</span></tt> type.</p>
 
486
</li>
 
487
<li><p class="first"><strong>PickleType() with mutable=True requires an __eq__()
 
488
method</strong> - The <tt class="docutils literal"><span class="pre">PickleType</span></tt> type needs to compare values
 
489
when mutable=True.  The method of comparing
 
490
<tt class="docutils literal"><span class="pre">pickle.dumps()</span></tt> is inefficient and unreliable.  If an
 
491
incoming object does not implement <tt class="docutils literal"><span class="pre">__eq__()</span></tt> and is
 
492
also not <tt class="docutils literal"><span class="pre">None</span></tt>, the <tt class="docutils literal"><span class="pre">dumps()</span></tt> comparison is used but
 
493
a warning is raised.  For types which implement
 
494
<tt class="docutils literal"><span class="pre">__eq__()</span></tt> which includes all dictionaries, lists, etc.,
 
495
comparison will use <tt class="docutils literal"><span class="pre">==</span></tt> and is now reliable by default.</p>
 
496
</li>
 
497
<li><p class="first"><strong>convert_bind_param() and convert_result_value() methods
 
498
of TypeEngine/TypeDecorator are removed.</strong> - The O&#8217;Reilly
 
499
book unfortunately documented these methods even though
 
500
they were deprecated post 0.3.   For a user-defined type
 
501
which subclasses <tt class="docutils literal"><span class="pre">TypeEngine</span></tt>, the <tt class="docutils literal"><span class="pre">bind_processor()</span></tt>
 
502
and <tt class="docutils literal"><span class="pre">result_processor()</span></tt> methods should be used for
 
503
bind/result processing.  Any user defined type, whether
 
504
extending <tt class="docutils literal"><span class="pre">TypeEngine</span></tt> or <tt class="docutils literal"><span class="pre">TypeDecorator</span></tt>, which uses
 
505
the old 0.3 style can be easily adapted to the new style
 
506
using the following adapter:</p>
 
507
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">AdaptOldConvertMethods</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
 
508
    <span class="sd">&quot;&quot;&quot;A mixin which adapts 0.3-style convert_bind_param and</span>
 
509
<span class="sd">    convert_result_value methods</span>
 
510
 
 
511
<span class="sd">    &quot;&quot;&quot;</span>
 
512
    <span class="k">def</span> <span class="nf">bind_processor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="p">):</span>
 
513
        <span class="k">def</span> <span class="nf">convert</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
 
514
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">convert_bind_param</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">dialect</span><span class="p">)</span>
 
515
        <span class="k">return</span> <span class="n">convert</span>
 
516
 
 
517
    <span class="k">def</span> <span class="nf">result_processor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="p">):</span>
 
518
        <span class="k">def</span> <span class="nf">convert</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
 
519
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">convert_result_value</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">dialect</span><span class="p">)</span>
 
520
        <span class="k">return</span> <span class="n">convert</span>
 
521
 
 
522
    <span class="k">def</span> <span class="nf">convert_result_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">dialect</span><span class="p">):</span>
 
523
        <span class="k">return</span> <span class="n">value</span>
 
524
 
 
525
    <span class="k">def</span> <span class="nf">convert_bind_param</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">dialect</span><span class="p">):</span>
 
526
        <span class="k">return</span> <span class="n">value</span></pre></div>
 
527
</div>
 
528
<p>To use the above mixin:</p>
 
529
<div class="highlight-python"><pre>class MyType(AdaptOldConvertMethods, TypeEngine):
 
530
   # ...</pre>
 
531
</div>
 
532
</li>
 
533
<li><p class="first">The <tt class="docutils literal"><span class="pre">quote</span></tt> flag on <tt class="docutils literal"><span class="pre">Column</span></tt> and <tt class="docutils literal"><span class="pre">Table</span></tt> as well as
 
534
the <tt class="docutils literal"><span class="pre">quote_schema</span></tt> flag on <tt class="docutils literal"><span class="pre">Table</span></tt> now control quoting
 
535
both positively and negatively.  The default is <tt class="docutils literal"><span class="pre">None</span></tt>,
 
536
meaning let regular quoting rules take effect. When
 
537
<tt class="docutils literal"><span class="pre">True</span></tt>, quoting is forced on.  When <tt class="docutils literal"><span class="pre">False</span></tt>, quoting
 
538
is forced off.</p>
 
539
</li>
 
540
<li><p class="first">Column <tt class="docutils literal"><span class="pre">DEFAULT</span></tt> value DDL can now be more conveniently
 
541
specified with <tt class="docutils literal"><span class="pre">Column(...,</span> <span class="pre">server_default='val')</span></tt>,
 
542
deprecating <tt class="docutils literal"><span class="pre">Column(...,</span> <span class="pre">PassiveDefault('val'))</span></tt>.
 
543
<tt class="docutils literal"><span class="pre">default=</span></tt> is now exclusively for Python-initiated
 
544
default values, and can coexist with server_default.  A
 
545
new <tt class="docutils literal"><span class="pre">server_default=FetchedValue()</span></tt> replaces the
 
546
<tt class="docutils literal"><span class="pre">PassiveDefault('')</span></tt> idiom for marking columns as
 
547
subject to influence from external triggers and has no DDL
 
548
side effects.</p>
 
549
</li>
 
550
<li><p class="first">SQLite&#8217;s <tt class="docutils literal"><span class="pre">DateTime</span></tt>, <tt class="docutils literal"><span class="pre">Time</span></tt> and <tt class="docutils literal"><span class="pre">Date</span></tt> types now
 
551
<strong>only accept datetime objects, not strings</strong> as bind
 
552
parameter input.  If you&#8217;d like to create your own
 
553
&#8220;hybrid&#8221; type which accepts strings and returns results as
 
554
date objects (from whatever format you&#8217;d like), create a
 
555
<tt class="docutils literal"><span class="pre">TypeDecorator</span></tt> that builds on <tt class="docutils literal"><span class="pre">String</span></tt>.  If you only
 
556
want string-based dates, just use <tt class="docutils literal"><span class="pre">String</span></tt>.</p>
 
557
</li>
 
558
<li><p class="first">Additionally, the <tt class="docutils literal"><span class="pre">DateTime</span></tt> and <tt class="docutils literal"><span class="pre">Time</span></tt> types, when
 
559
used with SQLite, now represent the &#8220;microseconds&#8221; field
 
560
of the Python <tt class="docutils literal"><span class="pre">datetime.datetime</span></tt> object in the same
 
561
manner as <tt class="docutils literal"><span class="pre">str(datetime)</span></tt> - as fractional seconds, not a
 
562
count of microseconds.  That is:</p>
 
563
<div class="highlight-python"><div class="highlight"><pre><span class="n">dt</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="p">(</span><span class="mi">2008</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">27</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">125</span><span class="p">)</span>  <span class="c"># 125 usec</span>
 
564
 
 
565
<span class="c"># old way</span>
 
566
<span class="s">&#39;2008-06-27 12:00:00.125&#39;</span>
 
567
 
 
568
<span class="c"># new way</span>
 
569
<span class="s">&#39;2008-06-27 12:00:00.000125&#39;</span></pre></div>
 
570
</div>
 
571
<p>So if an existing SQLite file-based database intends to be
 
572
used across 0.4 and 0.5, you either have to upgrade the
 
573
datetime columns to store the new format (NOTE: please
 
574
test this, I&#8217;m pretty sure its correct):</p>
 
575
<div class="highlight-python"><pre>UPDATE mytable SET somedatecol =
 
576
  substr(somedatecol, 0, 19) || '.' || substr((substr(somedatecol, 21, -1) / 1000000), 3, -1);</pre>
 
577
</div>
 
578
<p>or, enable &#8220;legacy&#8221; mode as follows:</p>
 
579
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.databases.sqlite</span> <span class="kn">import</span> <span class="n">DateTimeMixin</span>
 
580
<span class="n">DateTimeMixin</span><span class="o">.</span><span class="n">__legacy_microseconds__</span> <span class="o">=</span> <span class="bp">True</span></pre></div>
 
581
</div>
 
582
</li>
 
583
</ul>
 
584
</div>
 
585
<div class="section" id="connection-pool-no-longer-threadlocal-by-default">
 
586
<h2>Connection Pool no longer threadlocal by default<a class="headerlink" href="#connection-pool-no-longer-threadlocal-by-default" title="Permalink to this headline">¶</a></h2>
 
587
<p>0.4 has an unfortunate default setting of
 
588
&#8220;pool_threadlocal=True&#8221;, leading to surprise behavior when,
 
589
for example, using multiple Sessions within a single thread.
 
590
This flag is now off in 0.5.   To re-enable 0.4&#8217;s behavior,
 
591
specify <tt class="docutils literal"><span class="pre">pool_threadlocal=True</span></tt> to <tt class="docutils literal"><span class="pre">create_engine()</span></tt>, or
 
592
alternatively use the &#8220;threadlocal&#8221; strategy via
 
593
<tt class="docutils literal"><span class="pre">strategy=&quot;threadlocal&quot;</span></tt>.</p>
 
594
</div>
 
595
<div class="section" id="args-accepted-args-no-longer-accepted">
 
596
<h2>*args Accepted, *args No Longer Accepted<a class="headerlink" href="#args-accepted-args-no-longer-accepted" title="Permalink to this headline">¶</a></h2>
 
597
<p>The policy with <tt class="docutils literal"><span class="pre">method(\*args)</span></tt> vs. <tt class="docutils literal"><span class="pre">method([args])</span></tt>
 
598
is, if the method accepts a variable-length set of items
 
599
which represent a fixed structure, it takes <tt class="docutils literal"><span class="pre">\*args</span></tt>.  If
 
600
the method accepts a variable-length set of items that are
 
601
data-driven, it takes <tt class="docutils literal"><span class="pre">[args]</span></tt>.</p>
 
602
<ul>
 
603
<li><p class="first">The various Query.options() functions <tt class="docutils literal"><span class="pre">eagerload()</span></tt>,
 
604
<tt class="docutils literal"><span class="pre">eagerload_all()</span></tt>, <tt class="docutils literal"><span class="pre">lazyload()</span></tt>, <tt class="docutils literal"><span class="pre">contains_eager()</span></tt>,
 
605
<tt class="docutils literal"><span class="pre">defer()</span></tt>, <tt class="docutils literal"><span class="pre">undefer()</span></tt> all accept variable-length
 
606
<tt class="docutils literal"><span class="pre">\*keys</span></tt> as their argument now, which allows a path to
 
607
be formulated using descriptors, ie.:</p>
 
608
<div class="highlight-python"><div class="highlight"><pre><span class="n">query</span><span class="o">.</span><span class="n">options</span><span class="p">(</span><span class="n">eagerload_all</span><span class="p">(</span><span class="n">User</span><span class="o">.</span><span class="n">orders</span><span class="p">,</span> <span class="n">Order</span><span class="o">.</span><span class="n">items</span><span class="p">,</span> <span class="n">Item</span><span class="o">.</span><span class="n">keywords</span><span class="p">))</span></pre></div>
 
609
</div>
 
610
<p>A single array argument is still accepted for backwards
 
611
compatibility.</p>
 
612
</li>
 
613
<li><p class="first">Similarly, the <tt class="docutils literal"><span class="pre">Query.join()</span></tt> and <tt class="docutils literal"><span class="pre">Query.outerjoin()</span></tt>
 
614
methods accept a variable length *args, with a single
 
615
array accepted for backwards compatibility:</p>
 
616
<div class="highlight-python"><div class="highlight"><pre><span class="n">query</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s">&#39;orders&#39;</span><span class="p">,</span> <span class="s">&#39;items&#39;</span><span class="p">)</span>
 
617
<span class="n">query</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">User</span><span class="o">.</span><span class="n">orders</span><span class="p">,</span> <span class="n">Order</span><span class="o">.</span><span class="n">items</span><span class="p">)</span></pre></div>
 
618
</div>
 
619
</li>
 
620
<li><p class="first">the <tt class="docutils literal"><span class="pre">in_()</span></tt> method on columns and similar only accepts a
 
621
list argument now.  It no longer accepts <tt class="docutils literal"><span class="pre">\*args</span></tt>.</p>
 
622
</li>
 
623
</ul>
 
624
</div>
 
625
<div class="section" id="removed">
 
626
<h2>Removed<a class="headerlink" href="#removed" title="Permalink to this headline">¶</a></h2>
 
627
<ul>
 
628
<li><p class="first"><strong>entity_name</strong> - This feature was always problematic and
 
629
rarely used.  0.5&#8217;s more deeply fleshed out use cases
 
630
revealed further issues with <tt class="docutils literal"><span class="pre">entity_name</span></tt> which led to
 
631
its removal.  If different mappings are required for a
 
632
single class, break the class into separate subclasses and
 
633
map them separately.  An example of this is at
 
634
[wiki:UsageRecipes/EntityName].  More information
 
635
regarding rationale is described at http://groups.google.c
 
636
om/group/sqlalchemy/browse_thread/thread/9e23a0641a88b96d?
 
637
hl=en .</p>
 
638
</li>
 
639
<li><p class="first"><strong>get()/load() cleanup</strong></p>
 
640
<p>The <tt class="docutils literal"><span class="pre">load()</span></tt> method has been removed.  It&#8217;s
 
641
functionality was kind of arbitrary and basically copied
 
642
from Hibernate, where it&#8217;s also not a particularly
 
643
meaningful method.</p>
 
644
<p>To get equivalent functionality:</p>
 
645
<div class="highlight-python"><div class="highlight"><pre><span class="n">x</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">SomeClass</span><span class="p">)</span><span class="o">.</span><span class="n">populate_existing</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span></pre></div>
 
646
</div>
 
647
<p><tt class="docutils literal"><span class="pre">Session.get(cls,</span> <span class="pre">id)</span></tt> and <tt class="docutils literal"><span class="pre">Session.load(cls,</span> <span class="pre">id)</span></tt>
 
648
have been removed.  <tt class="docutils literal"><span class="pre">Session.get()</span></tt> is redundant vs.
 
649
<tt class="docutils literal"><span class="pre">session.query(cls).get(id)</span></tt>.</p>
 
650
<p><tt class="docutils literal"><span class="pre">MapperExtension.get()</span></tt> is also removed (as is
 
651
<tt class="docutils literal"><span class="pre">MapperExtension.load()</span></tt>).  To override the
 
652
functionality of <tt class="docutils literal"><span class="pre">Query.get()</span></tt>, use a subclass:</p>
 
653
<div class="highlight-python"><pre>class MyQuery(Query):
 
654
    def get(self, ident):
 
655
        # ...
 
656
 
 
657
session = sessionmaker(query_cls=MyQuery)()
 
658
 
 
659
ad1 = session.query(Address).get(1)</pre>
 
660
</div>
 
661
</li>
 
662
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.orm.relation()</span></tt></p>
 
663
<p>The following deprecated keyword arguments have been
 
664
removed:</p>
 
665
<p>foreignkey, association, private, attributeext, is_backref</p>
 
666
<p>In particular, <tt class="docutils literal"><span class="pre">attributeext</span></tt> is replaced with
 
667
<tt class="docutils literal"><span class="pre">extension</span></tt> - the <tt class="docutils literal"><span class="pre">AttributeExtension</span></tt> class is now in
 
668
the public API.</p>
 
669
</li>
 
670
<li><p class="first"><tt class="docutils literal"><span class="pre">session.Query()</span></tt></p>
 
671
<p>The following deprecated functions have been removed:</p>
 
672
<p>list, scalar, count_by, select_whereclause, get_by,
 
673
select_by, join_by, selectfirst, selectone, select,
 
674
execute, select_statement, select_text, join_to, join_via,
 
675
selectfirst_by, selectone_by, apply_max, apply_min,
 
676
apply_avg, apply_sum</p>
 
677
<p>Additionally, the <tt class="docutils literal"><span class="pre">id</span></tt> keyword argument to <tt class="docutils literal"><span class="pre">join()</span></tt>,
 
678
<tt class="docutils literal"><span class="pre">outerjoin()</span></tt>, <tt class="docutils literal"><span class="pre">add_entity()</span></tt> and <tt class="docutils literal"><span class="pre">add_column()</span></tt> has
 
679
been removed.  To target table aliases in <tt class="docutils literal"><span class="pre">Query</span></tt> to
 
680
result columns, use the <tt class="docutils literal"><span class="pre">aliased</span></tt> construct:</p>
 
681
<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">aliased</span>
 
682
<span class="n">address_alias</span> <span class="o">=</span> <span class="n">aliased</span><span class="p">(</span><span class="n">Address</span><span class="p">)</span>
 
683
<span class="k">print</span> <span class="n">session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">User</span><span class="p">,</span> <span class="n">address_alias</span><span class="p">)</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">address_alias</span><span class="p">,</span> <span class="n">User</span><span class="o">.</span><span class="n">addresses</span><span class="p">))</span><span class="o">.</span><span class="n">all</span><span class="p">()</span></pre></div>
 
684
</div>
 
685
</li>
 
686
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.orm.Mapper</span></tt></p>
 
687
<ul class="simple">
 
688
<li>instances()</li>
 
689
<li>get_session() - this method was not very noticeable, but
 
690
had the effect of associating lazy loads with a
 
691
particular session even if the parent object was
 
692
entirely detached, when an extension such as
 
693
<tt class="docutils literal"><span class="pre">scoped_session()</span></tt> or the old <tt class="docutils literal"><span class="pre">SessionContextExt</span></tt>
 
694
was used.  It&#8217;s possible that some applications which
 
695
relied upon this behavior will no longer work as
 
696
expected;  but the better programming practice here is
 
697
to always ensure objects are present within sessions if
 
698
database access from their attributes are required.</li>
 
699
</ul>
 
700
</li>
 
701
<li><p class="first"><tt class="docutils literal"><span class="pre">mapper(MyClass,</span> <span class="pre">mytable)</span></tt></p>
 
702
<p>Mapped classes no are longer instrumented with a &#8220;c&#8221; class
 
703
attribute; e.g. <tt class="docutils literal"><span class="pre">MyClass.c</span></tt></p>
 
704
</li>
 
705
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.orm.collections</span></tt></p>
 
706
<p>The _prepare_instrumentation alias for
 
707
prepare_instrumentation has been removed.</p>
 
708
</li>
 
709
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.orm</span></tt></p>
 
710
<p>Removed the <tt class="docutils literal"><span class="pre">EXT_PASS</span></tt> alias of <tt class="docutils literal"><span class="pre">EXT_CONTINUE</span></tt>.</p>
 
711
</li>
 
712
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.engine</span></tt></p>
 
713
<p>The alias from <tt class="docutils literal"><span class="pre">DefaultDialect.preexecute_sequences</span></tt> to
 
714
<tt class="docutils literal"><span class="pre">.preexecute_pk_sequences</span></tt> has been removed.</p>
 
715
<p>The deprecated engine_descriptors() function has been
 
716
removed.</p>
 
717
</li>
 
718
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.ext.activemapper</span></tt></p>
 
719
<p>Module removed.</p>
 
720
</li>
 
721
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.ext.assignmapper</span></tt></p>
 
722
<p>Module removed.</p>
 
723
</li>
 
724
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.ext.associationproxy</span></tt></p>
 
725
<p>Pass-through of keyword args on the proxy&#8217;s
 
726
<tt class="docutils literal"><span class="pre">.append(item,</span> <span class="pre">\**kw)</span></tt> has been removed and is now
 
727
simply <tt class="docutils literal"><span class="pre">.append(item)</span></tt></p>
 
728
</li>
 
729
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.ext.selectresults</span></tt>,
 
730
<tt class="docutils literal"><span class="pre">sqlalchemy.mods.selectresults</span></tt></p>
 
731
<p>Modules removed.</p>
 
732
</li>
 
733
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.ext.declarative</span></tt></p>
 
734
<p><tt class="docutils literal"><span class="pre">declared_synonym()</span></tt> removed.</p>
 
735
</li>
 
736
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.ext.sessioncontext</span></tt></p>
 
737
<p>Module removed.</p>
 
738
</li>
 
739
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.log</span></tt></p>
 
740
<p>The <tt class="docutils literal"><span class="pre">SADeprecationWarning</span></tt> alias to
 
741
<tt class="docutils literal"><span class="pre">sqlalchemy.exc.SADeprecationWarning</span></tt> has been removed.</p>
 
742
</li>
 
743
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.exc</span></tt></p>
 
744
<p><tt class="docutils literal"><span class="pre">exc.AssertionError</span></tt> has been removed and usage replaced
 
745
by the Python built-in of the same name.</p>
 
746
</li>
 
747
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.databases.mysql</span></tt></p>
 
748
<p>The deprecated <tt class="docutils literal"><span class="pre">get_version_info</span></tt> dialect method has
 
749
been removed.</p>
 
750
</li>
 
751
</ul>
 
752
</div>
 
753
<div class="section" id="renamed-or-moved">
 
754
<h2>Renamed or Moved<a class="headerlink" href="#renamed-or-moved" title="Permalink to this headline">¶</a></h2>
 
755
<ul>
 
756
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.exceptions</span></tt> is now <tt class="docutils literal"><span class="pre">sqlalchemy.exc</span></tt></p>
 
757
<p>The module may still be imported under the old name until
 
758
0.6.</p>
 
759
</li>
 
760
<li><p class="first"><tt class="docutils literal"><span class="pre">FlushError</span></tt>, <tt class="docutils literal"><span class="pre">ConcurrentModificationError</span></tt>,
 
761
<tt class="docutils literal"><span class="pre">UnmappedColumnError</span></tt> -&gt; sqlalchemy.orm.exc</p>
 
762
<p>These exceptions moved to the orm package.  Importing
 
763
&#8216;sqlalchemy.orm&#8217; will install aliases in sqlalchemy.exc
 
764
for compatibility until 0.6.</p>
 
765
</li>
 
766
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.logging</span></tt> -&gt; <tt class="docutils literal"><span class="pre">sqlalchemy.log</span></tt></p>
 
767
<p>This internal module was renamed.  No longer needs to be
 
768
special cased when packaging SA with py2app and similar
 
769
tools that scan imports.</p>
 
770
</li>
 
771
<li><p class="first"><tt class="docutils literal"><span class="pre">session.Query().iterate_instances()</span></tt> -&gt;
 
772
<tt class="docutils literal"><span class="pre">session.Query().instances()</span></tt>.</p>
 
773
</li>
 
774
</ul>
 
775
</div>
 
776
<div class="section" id="deprecated">
 
777
<h2>Deprecated<a class="headerlink" href="#deprecated" title="Permalink to this headline">¶</a></h2>
 
778
<ul>
 
779
<li><p class="first"><tt class="docutils literal"><span class="pre">Session.save()</span></tt>, <tt class="docutils literal"><span class="pre">Session.update()</span></tt>,
 
780
<tt class="docutils literal"><span class="pre">Session.save_or_update()</span></tt></p>
 
781
<p>All three replaced by <tt class="docutils literal"><span class="pre">Session.add()</span></tt></p>
 
782
</li>
 
783
<li><p class="first"><tt class="docutils literal"><span class="pre">sqlalchemy.PassiveDefault</span></tt></p>
 
784
<p>Use <tt class="docutils literal"><span class="pre">Column(server_default=...)</span></tt> Translates to
 
785
sqlalchemy.DefaultClause() under the hood.</p>
 
786
</li>
 
787
<li><p class="first"><tt class="docutils literal"><span class="pre">session.Query().iterate_instances()</span></tt>. It has been
 
788
renamed to <tt class="docutils literal"><span class="pre">instances()</span></tt>.</p>
 
789
</li>
 
790
</ul>
 
791
</div>
 
792
</div>
 
793
 
 
794
    </div>
 
795
 
 
796
</div>
 
797
 
 
798
<div id="docs-bottom-navigation" class="docs-navigation-links">
 
799
        Previous:
 
800
        <a href="migration_06.html" title="previous chapter">What&#8217;s New in SQLAlchemy 0.6?</a>
 
801
        Next:
 
802
        <a href="migration_04.html" title="next chapter">What&#8217;s new in SQLAlchemy 0.4?</a>
 
803
 
 
804
    <div id="docs-copyright">
 
805
        &copy; <a href="../copyright.html">Copyright</a> 2007-2013, the SQLAlchemy authors and contributors.
 
806
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
 
807
    </div>
 
808
</div>
 
809
 
 
810
</div>
 
811
 
 
812
        
 
813
    </body>
 
814
</html>
 
815
 
 
816