This commit is contained in:
Mike Bayer
2005-09-15 04:06:09 +00:00
parent 8d505a9810
commit 183b993df1
2 changed files with 21 additions and 20 deletions
+18 -17
View File
@@ -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=<column>"
# 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=<column>"
else:
self.foreignkey = w.dependent
if not hasattr(parent.class_, key):
setattr(parent.class_, key, SmartProperty(key).property(usehistory = True, uselist = self.uselist))
+3 -3
View File
@@ -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"