[Sqlalchemy-commits] [1303] sqlalchemy/branches/schema/lib/sqlalchemy/mapping/mapper.py: factored ad
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-04-20 02:30:34
|
<!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>[1303] sqlalchemy/branches/schema/lib/sqlalchemy/mapping/mapper.py: factored add_property into one method, added add_properties</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1303</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-04-19 21:30:21 -0500 (Wed, 19 Apr 2006)</dd> </dl> <h3>Log Message</h3> <pre>factored add_property into one method, added add_properties</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemybranchesschemalibsqlalchemymappingmapperpy">sqlalchemy/branches/schema/lib/sqlalchemy/mapping/mapper.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemybranchesschemalibsqlalchemymappingmapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/mapping/mapper.py (1302 => 1303)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/mapping/mapper.py 2006-04-20 01:49:31 UTC (rev 1302) +++ sqlalchemy/branches/schema/lib/sqlalchemy/mapping/mapper.py 2006-04-20 02:30:21 UTC (rev 1303) </span><span class="lines">@@ -158,25 +158,7 @@ </span><span class="cx"> # load custom properties </span><span class="cx"> if properties is not None: </span><span class="cx"> for key, prop in properties.iteritems(): </span><del>- if sql.is_column(prop): - try: - prop = self.table._get_col_by_original(prop) - except KeyError: - raise ArgumentError("Column '%s' is not represented in mapper's table" % prop._label) - self.columns[key] = prop - prop = ColumnProperty(prop) - elif isinstance(prop, list) and sql.is_column(prop[0]): - try: - prop = [self.table._get_col_by_original(p) for p in prop] - except KeyError, e: - raise ArgumentError("Column '%s' is not represented in mapper's table" % e.args[0]) - self.columns[key] = prop[0] - prop = ColumnProperty(*prop) - self.props[key] = prop - if isinstance(prop, ColumnProperty): - for col in prop.columns: - proplist = self.columntoproperty.setdefault(col.original, []) - proplist.append(prop) </del><ins>+ self.add_property(key, prop, False) </ins><span class="cx"> </span><span class="cx"> # load properties from the main table object, </span><span class="cx"> # not overriding those set up in the 'properties' argument </span><span class="lines">@@ -299,22 +281,41 @@ </span><span class="cx"> </span><span class="cx"> def select_text(self, text, **params): </span><span class="cx"> return self.query.select_text(text, **params) </span><ins>+ + def add_properties(self, dict_of_properties): + """adds the given dictionary of properties to this mapper, using add_property.""" + for key, value in dict_of_properties.iteritems(): + self.add_property(key, value, True) </ins><span class="cx"> </span><del>- def add_property(self, key, prop): </del><ins>+ def add_property(self, key, prop, init=True): </ins><span class="cx"> """adds an additional property to this mapper. this is the same as if it were </span><span class="cx"> specified within the 'properties' argument to the constructor. if the named </span><span class="cx"> property already exists, this will replace it. Useful for </span><span class="cx"> circular relationships, or overriding the parameters of auto-generated properties </span><span class="cx"> such as backreferences.""" </span><ins>+ </ins><span class="cx"> if sql.is_column(prop): </span><ins>+ try: + prop = self.table._get_col_by_original(prop) + except KeyError: + raise ArgumentError("Column '%s' is not represented in mapper's table" % prop._label) </ins><span class="cx"> self.columns[key] = prop </span><span class="cx"> prop = ColumnProperty(prop) </span><ins>+ elif isinstance(prop, list) and sql.is_column(prop[0]): + try: + prop = [self.table._get_col_by_original(p) for p in prop] + except KeyError, e: + raise ArgumentError("Column '%s' is not represented in mapper's table" % e.args[0]) + self.columns[key] = prop[0] + prop = ColumnProperty(*prop) </ins><span class="cx"> self.props[key] = prop </span><span class="cx"> if isinstance(prop, ColumnProperty): </span><span class="cx"> for col in prop.columns: </span><span class="cx"> proplist = self.columntoproperty.setdefault(col.original, []) </span><span class="cx"> proplist.append(prop) </span><del>- prop.init(key, self) </del><ins>+ + if init: + prop.init(key, self) </ins><span class="cx"> </span><span class="cx"> def __str__(self): </span><span class="cx"> return "Mapper|" + self.class_.__name__ + "|" + (self.entity_name is not None and "/%s" % self.entity_name or "") + self.primarytable.name </span></span></pre> </div> </div> </body> </html> |