From 183b993df1908d3dac3c28ab9516abd4777fa2a7 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 15 Sep 2005 04:06:09 +0000 Subject: [PATCH] --- lib/sqlalchemy/mapper.py | 35 ++++++++++++++++++----------------- lib/sqlalchemy/objectstore.py | 6 +++--- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/sqlalchemy/mapper.py b/lib/sqlalchemy/mapper.py index 910823afd7..808a639146 100644 --- a/lib/sqlalchemy/mapper.py +++ b/lib/sqlalchemy/mapper.py @@ -175,7 +175,7 @@ class Mapper(object): except KeyError: clause = sql.and_() i = 0 - for primary_key in self.primary_keys[table]: + for primary_key in self.primary_keys[self.table]: # appending to the and_'s clause list directly to skip # typechecks etc. clause.clauses.append(primary_key == ident[i]) @@ -237,14 +237,15 @@ class Mapper(object): work[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) - else: - work[table]['insert'].append((obj, params)) + for table in self.tables: + params = {} + for col in table.columns: + params[col.key] = self._getattrbycolumn(obj, col) + + if hasattr(obj, "_instance_key"): + work[table]['update'].append(params) + else: + work[table]['insert'].append((obj, params)) for table, stuff in work.iteritems(): if len(stuff['update']): @@ -417,7 +418,7 @@ class PropertyLoader(MapperProperty): self.key = key self.parent = parent - # if join conditions were not specified, figure them out based on primary keys + # if join conditions were not specified, figure them out based on foreign keys if self.secondary is not None: if self.secondaryjoin is None: self.secondaryjoin = self.match_primaries(self.target, self.secondary) @@ -430,15 +431,15 @@ class PropertyLoader(MapperProperty): # if the foreign key wasnt specified and theres no assocaition table, try to figure # out who is dependent on who. we dont need all the foreign keys represented in the join, # just one of them. -# if self.foreignkey is None and self.secondaryjoin is None: + if self.foreignkey is None and self.secondaryjoin is None: # else we usually will have a one-to-many where the secondary depends on the primary # but its possible that its reversed -# w = PropertyLoader.FindDependent() -# self.primaryjoin.accept_visitor(w) -# if w.dependent is None: -# raise "cant determine primary foreign key in the join relationship....specify foreignkey=" -# else: -# self.foreignkey = w.dependent + w = PropertyLoader.FindDependent() + self.primaryjoin.accept_visitor(w) + if w.dependent is None: + raise "cant determine primary foreign key in the join relationship....specify foreignkey=" + else: + self.foreignkey = w.dependent if not hasattr(parent.class_, key): setattr(parent.class_, key, SmartProperty(key).property(usehistory = True, uselist = self.uselist)) diff --git a/lib/sqlalchemy/objectstore.py b/lib/sqlalchemy/objectstore.py index aefd981230..cd6cbb9bf8 100644 --- a/lib/sqlalchemy/objectstore.py +++ b/lib/sqlalchemy/objectstore.py @@ -37,7 +37,7 @@ def get_id_key(ident, class_, table): return value: a tuple object which is used as an identity key. """ return (class_, table, tuple(ident)) -def get_instance_key(object, class_, table, primary_keys): +def get_instance_key(object, class_, table, primary_keys, mapper): """returns an identity-map key for use in storing/retrieving an item from the identity map, given the object instance itself. @@ -49,7 +49,8 @@ def get_instance_key(object, class_, table, primary_keys): may be synonymous with the table argument or can be a larger construct containing that table. return value: a tuple object which is used as an identity key. """ - return (class_, table, tuple([getattr(object, column.key, None) for column in primary_keys])) + # TODO: clean this up, too many args, too confusing + return (class_, table, tuple([mapper._getattrbycolumn(object, column) for column in primary_keys])) def get_row_key(row, class_, table, primary_keys): """returns an identity-map key for use in storing/retrieving an item from the identity map, given a result set row. @@ -74,7 +75,6 @@ def get(key): return val def put(key, obj, scope='thread'): - if isinstance(obj, dict): raise "cant put a dict in the object store" -- 2.47.2