Order operation on relational field to avoid constraints

The order on which the operations are applied can trigger constraints.
So it is safer to first delete then write and finally create.

issue6790
review43511002
This commit is contained in:
Cédric Krier committed 2017-09-28 23:44:48 +02:00
1 parent a6688da3d3
commit 83656053c8
3 files changed
+11 -8

No files matched your search

+5 -4
View File
@@ -233,14 +233,15 @@ class Many2Many(Field):
action = value[0]
args = value[1:]
actions[action](ids, *args)
if relation_to_create:
Relation.create(relation_to_create)
# Ordered operations to avoid uniqueness/overlapping constraints
if relation_to_delete:
Relation.delete(relation_to_delete)
if target_to_write:
Target.write(*target_to_write)
if target_to_delete:
Target.delete(target_to_delete)
if target_to_write:
Target.write(*target_to_write)
if relation_to_create:
Relation.create(relation_to_create)
def get_target(self):
'Return the target model'
+5 -4
View File
@@ -213,12 +213,13 @@ class One2Many(Field):
action = value[0]
args = value[1:]
actions[action](ids, *args)
if to_create:
Target.create(to_create)
if to_write:
Target.write(*to_write)
# Ordered operations to avoid uniqueness/overlapping constraints
if to_delete:
Target.delete(to_delete)
if to_write:
Target.write(*to_write)
if to_create:
Target.create(to_create)
def get_target(self):
'Return the target Model'
+1
View File
@@ -47,6 +47,7 @@ class One2One(Many2Many):
self.origin: record_id,
self.target: value,
})
# Ordered operations to avoid uniqueness/overlapping constraints
if to_delete:
Relation.delete(to_delete)
if to_create: