[Sqlalchemy-commits] [5812] sqlalchemy/trunk: - Declarative will accept a table-bound column as a p
Brought to you by:
zzzeek
From: <co...@sq...> - 2009-02-22 19:35:41
|
<!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><meta http-equiv="content-type" content="text/html; charset=utf-8" /><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, #header, #footer { 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; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #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>[5812] sqlalchemy/trunk: - Declarative will accept a table-bound column as a property</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>5812</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2009-02-22 14:35:36 -0500 (Sun, 22 Feb 2009)</dd> </dl> <h3>Log Message</h3> <pre>- Declarative will accept a table-bound column as a property when used in conjunction with __table__, if the column is already present in __table__. The column will be remapped to the given key the same way as when added to the mapper() properties dict.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunkCHANGES">sqlalchemy/trunk/CHANGES</a></li> <li><a href="#sqlalchemytrunklibsqlalchemyextdeclarativepy">sqlalchemy/trunk/lib/sqlalchemy/ext/declarative.py</a></li> <li><a href="#sqlalchemytrunktestextdeclarativepy">sqlalchemy/trunk/test/ext/declarative.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunkCHANGES"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/CHANGES (5811 => 5812)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/CHANGES 2009-02-20 15:45:25 UTC (rev 5811) +++ sqlalchemy/trunk/CHANGES 2009-02-22 19:35:36 UTC (rev 5812) </span><span class="lines">@@ -108,6 +108,11 @@ </span><span class="cx"> - Declarative will properly interpret the "foreign_keys" argument </span><span class="cx"> on a backref() if it's a string. </span><span class="cx"> </span><ins>+ - Declarative will accept a table-bound column as a property + when used in conjunction with __table__, if the column is already + present in __table__. The column will be remapped to the given + key the same way as when added to the mapper() properties dict. + </ins><span class="cx"> 0.5.2 </span><span class="cx"> ====== </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunklibsqlalchemyextdeclarativepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/ext/declarative.py (5811 => 5812)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/ext/declarative.py 2009-02-20 15:45:25 UTC (rev 5811) +++ sqlalchemy/trunk/lib/sqlalchemy/ext/declarative.py 2009-02-22 19:35:36 UTC (rev 5812) </span><span class="lines">@@ -480,7 +480,9 @@ </span><span class="cx"> else: </span><span class="cx"> table = cls.__table__ </span><span class="cx"> if cols: </span><del>- raise exceptions.ArgumentError("Can't add additional columns when specifying __table__") </del><ins>+ for c in cols: + if not table.c.contains_column(c): + raise exceptions.ArgumentError("Can't add additional column %r when specifying __table__" % key) </ins><span class="cx"> </span><span class="cx"> mapper_args = getattr(cls, '__mapper_args__', {}) </span><span class="cx"> if 'inherits' not in mapper_args: </span></span></pre></div> <a id="sqlalchemytrunktestextdeclarativepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/ext/declarative.py (5811 => 5812)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/ext/declarative.py 2009-02-20 15:45:25 UTC (rev 5811) +++ sqlalchemy/trunk/test/ext/declarative.py 2009-02-22 19:35:36 UTC (rev 5812) </span><span class="lines">@@ -65,12 +65,20 @@ </span><span class="cx"> self.assertRaisesMessage(sa.exc.InvalidRequestError, "does not have a __table__", go) </span><span class="cx"> </span><span class="cx"> def test_cant_add_columns(self): </span><del>- t = Table('t', Base.metadata, Column('id', Integer, primary_key=True)) </del><ins>+ t = Table('t', Base.metadata, Column('id', Integer, primary_key=True), Column('data', String)) </ins><span class="cx"> def go(): </span><span class="cx"> class User(Base): </span><span class="cx"> __table__ = t </span><span class="cx"> foo = Column(Integer, primary_key=True) </span><del>- self.assertRaisesMessage(sa.exc.ArgumentError, "add additional columns", go) </del><ins>+ # can't specify new columns not already in the table + self.assertRaisesMessage(sa.exc.ArgumentError, "Can't add additional column 'foo' when specifying __table__", go) + + # regular re-mapping works tho + class Bar(Base): + __table__ = t + some_data = t.c.data + + assert class_mapper(Bar).get_property('some_data').columns[0] is t.c.data </ins><span class="cx"> </span><span class="cx"> def test_undefer_column_name(self): </span><span class="cx"> # TODO: not sure if there was an explicit </span></span></pre> </div> </div> </body> </html> |