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:
1 parent
a6688da3d3
commit
83656053c8
3 files changed
+11
-8
No files matched your search
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user