[Sqlalchemy-commits] [1220] sqlalchemy/trunk: tweak to mapper to allow inheritance on the same table
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-03-27 02:58:33
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1220] sqlalchemy/trunk: tweak to mapper to allow inheritance on the same table.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1220</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-03-26 20:58:20 -0600 (Sun, 26 Mar 2006)</dd> </dl> <h3>Log Message</h3> <pre>tweak to mapper to allow inheritance on the same table.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunkCHANGES">sqlalchemy/trunk/CHANGES</a></li> <li><a href="#sqlalchemytrunklibsqlalchemymappingmapperpy">sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunkCHANGES"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/CHANGES (1219 => 1220)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/CHANGES 2006-03-27 02:02:06 UTC (rev 1219) +++ sqlalchemy/trunk/CHANGES 2006-03-27 02:58:20 UTC (rev 1220) </span><span class="lines">@@ -31,6 +31,8 @@ </span><span class="cx"> concept of relations on a mapper being made towards the "local" table for that </span><span class="cx"> mapper, not the tables it inherits. allows more complex compositional patterns </span><span class="cx"> to work with lazy/eager loading. </span><ins>+- added support for mappers to inherit from others based on the same table, +just specify the same table as that of both parent/child mapper. </ins><span class="cx"> - some minor speed improvements to the attributes system with regards to </span><span class="cx"> instantiating and populating new objects. </span><span class="cx"> - fixed MySQL binary unit test </span></span></pre></div> <a id="sqlalchemytrunklibsqlalchemymappingmapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py (1219 => 1220)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py 2006-03-27 02:02:06 UTC (rev 1219) +++ sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py 2006-03-27 02:58:20 UTC (rev 1220) </span><span class="lines">@@ -71,22 +71,24 @@ </span><span class="cx"> if inherits is not None: </span><span class="cx"> self.primarytable = inherits.primarytable </span><span class="cx"> # inherit_condition is optional. </span><del>- if inherit_condition is None: - # figure out inherit condition from our table to the immediate table - # of the inherited mapper, not its full table which could pull in other - # stuff we dont want (allows test/inheritance.InheritTest4 to pass) - inherit_condition = sql.join(inherits.noninherited_table, table).onclause - self.table = sql.join(inherits.table, table, inherit_condition) - #print "inherit condition", str(self.table.onclause) </del><ins>+ if not table is inherits.noninherited_table: + if inherit_condition is None: + # figure out inherit condition from our table to the immediate table + # of the inherited mapper, not its full table which could pull in other + # stuff we dont want (allows test/inheritance.InheritTest4 to pass) + inherit_condition = sql.join(inherits.noninherited_table, table).onclause + self.table = sql.join(inherits.table, table, inherit_condition) + #print "inherit condition", str(self.table.onclause) </ins><span class="cx"> </span><del>- # generate sync rules. similarly to creating the on clause, specify a - # stricter set of tables to create "sync rules" by,based on the immediate - # inherited table, rather than all inherited tables - self._synchronizer = sync.ClauseSynchronizer(self, self, sync.ONETOMANY) - self._synchronizer.compile(self.table.onclause, util.HashSet([inherits.noninherited_table]), TableFinder(table)) - # the old rule - #self._synchronizer.compile(self.table.onclause, inherits.tables, TableFinder(table)) - </del><ins>+ # generate sync rules. similarly to creating the on clause, specify a + # stricter set of tables to create "sync rules" by,based on the immediate + # inherited table, rather than all inherited tables + self._synchronizer = sync.ClauseSynchronizer(self, self, sync.ONETOMANY) + self._synchronizer.compile(self.table.onclause, util.HashSet([inherits.noninherited_table]), TableFinder(table)) + # the old rule + #self._synchronizer.compile(self.table.onclause, inherits.tables, TableFinder(table)) + else: + self._synchronizer = None </ins><span class="cx"> self.inherits = inherits </span><span class="cx"> self.noninherited_table = table </span><span class="cx"> else: </span></span></pre> </div> </div> </body> </html> |