From: Mike Bayer Date: Thu, 15 Sep 2005 05:18:15 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rel_0_1_0~729 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=590f19e19090d8ce1edb19f15fd20ca2d5c56e3b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git --- diff --git a/lib/sqlalchemy/mapper.py b/lib/sqlalchemy/mapper.py index 808a639146..4d9ea37102 100644 --- a/lib/sqlalchemy/mapper.py +++ b/lib/sqlalchemy/mapper.py @@ -186,7 +186,8 @@ class Mapper(object): return None def put(self, instance): - key = objectstore.get_instance_key(instance, self.class_, self.table, self.primary_keys[self.selectable]) + key = objectstore.get_instance_key(instance, self.class_, self.table, self.primary_keys[self.selectable], self) + print repr(instance.__dict__) objectstore.put(key, instance, self.scope) return key @@ -232,34 +233,36 @@ class Mapper(object): def save_obj(self, objects): # try to get inserts to be en-masse with the "guess-the-id" thing maybe - work = {} - for table in self.tables: - work[table] = {'insert': [], 'update': []} - for obj in objects: - for table in self.tables: + for table in self.tables: + # loop thru tables in the outer loop, objects on the inner loop. + # this is important for an object represented across two tables + # so that it gets its primary keys populated for the benefit of the + # second table. + insert = [] + update = [] + for obj in objects: params = {} for col in table.columns: params[col.key] = self._getattrbycolumn(obj, col) if hasattr(obj, "_instance_key"): - work[table]['update'].append(params) + update.append(params) else: - work[table]['insert'].append((obj, params)) + insert.append((obj, params)) - for table, stuff in work.iteritems(): - if len(stuff['update']): + if len(update): clause = sql.and_() for col in self.primary_keys[table]: clause.clauses.append(col == sql.bindparam(col.key)) statement = table.update(clause) statement.echo = self.echo - statement.execute(*stuff['update']) + statement.execute(*update) - if len(stuff['insert']): + if len(insert): statement = table.insert() statement.echo = self.echo - for rec in stuff['insert']: + for rec in insert: (obj, params) = rec statement.execute(**params) primary_key = table.engine.last_inserted_ids()[0]