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])
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']):
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)
# 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))
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.
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.
return val
def put(key, obj, scope='thread'):
-
if isinstance(obj, dict):
raise "cant put a dict in the object store"