fixed uniqueness problem in archives

This commit is contained in:
mdipierro
2012-07-17 10:59:26 -05:00
parent ac75bbdc9c
commit f3ea2d1cc6
3 changed files with 16 additions and 9 deletions
+11 -5
View File
@@ -7130,10 +7130,8 @@ class Table(dict):
table = field
for field in table:
if not field.name in fieldnames and not field.type=='id':
field = copy.copy(field)
# correct self references
if not table._actual and field.type == 'reference '+table._tablename:
field.type = 'reference '+self._tablename
t2 = not table._actual and self._tablename
field = field.clone(point_self_references_to=t2)
newfields.append(field)
fieldnames.add(field.name)
else:
@@ -7210,7 +7208,7 @@ class Table(dict):
archive_table = archive_db.define_table(
archive_name,
Field(current_record,field_type),
self)
*[field.close(unique=False) for field in self])
self._before_update.append(
lambda qset,fs,at=archive_table,cn=current_record:
archive_record(qset,fs,at,cn))
@@ -8038,6 +8036,14 @@ class Field(Expression):
else:
self.requires = requires
def clone(self,point_self_references_to=False,**args):
field = copy.copy(self)
if point_self_references_to and \
field.type == 'reference %s'+field._tablename:
field.type = 'reference %s' % point_self_references_to
field.__dict__.update(args)
return field
def store(self, file, filename=None, path=None):
if self.custom_store:
return self.custom_store(file,filename,path)