added append_item() method to column to work similarly to table.append_item(), used to
append foreign keys to the column (required in mysql)
appending new foreign keys will properly replace the old one, so explicitly appending
foreign keys to tables will replace those loaded via table reflection (instead of doubling them up)
table.c[constrained_column]._set_primary_key()
elif type=='FOREIGN KEY':
remotetable = Table(referred_table, engine, autoload = True, schema=referred_schema)
- table.c[constrained_column].foreign_key = schema.ForeignKey(remotetable.c[referred_column])
+ table.c[constrained_column].append_item(schema.ForeignKey(remotetable.c[referred_column]))
+
(tablename, localcol, remotecol) = (row[2], row[3], row[4])
#print "row! " + repr(row)
remotetable = Table(tablename, self, autoload = True)
- table.c[localcol].foreign_key = schema.ForeignKey(remotetable.c[remotecol])
+ table.c[localcol].append_item(schema.ForeignKey(remotetable.c[remotecol]))
# check for UNIQUE indexes
c = self.execute("PRAGMA index_list(" + table.name + ")", {})
unique_indexes = []
original = property(lambda s: s._orig or s)
engine = property(lambda s: s.table.engine)
+ def append_item(self, item):
+ self._init_items(item)
+
def _set_primary_key(self):
if self.primary_key:
return
def _set_parent(self, column):
self.parent = column
+ # if a foreign key was already set up for this, replace it with
+ # this one, including removing from the parent
+ if self.parent.foreign_key is not None:
+ self.parent.table.foreign_keys.remove(self.parent.foreign_key)
self.parent.foreign_key = self
self.parent.table.foreign_keys.append(self)
users.create()
addresses.create()
-
- addresses.drop()
- users.drop()
+ try:
+ # create a join from the two tables, this insures that
+ # theres a foreign key set up
+# addresses.c.remote_user_id.append_item(ForeignKey('engine_users.user_id'))
+ j = join(users, addresses)
+ print str(j.onclause)
+ self.assert_((users.c.user_id==addresses.c.remote_user_id).compare(j.onclause))
+ finally:
+ addresses.drop()
+ users.drop()
def testmultipk(self):
table = Table(