call root record delete first
This commit is contained in:
parent
9cf5e28700
commit
e60f470188
|
@ -370,6 +370,12 @@ func (dao *Dao) DeleteRecord(record *models.Record) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return dao.RunInTransaction(func(txDao *Dao) error {
|
return dao.RunInTransaction(func(txDao *Dao) error {
|
||||||
|
// always delete the record first to ensure that there will be no "A<->B"
|
||||||
|
// relations to prevent deadlock when calling DeleteRecord recursively
|
||||||
|
if err := txDao.Delete(record); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// check if related records has to be deleted (if `CascadeDelete` is set)
|
// check if related records has to be deleted (if `CascadeDelete` is set)
|
||||||
// OR
|
// OR
|
||||||
// just unset the record id from any relation field values (if they are not required)
|
// just unset the record id from any relation field values (if they are not required)
|
||||||
|
@ -414,7 +420,7 @@ func (dao *Dao) DeleteRecord(record *models.Record) error {
|
||||||
if err := txDao.DeleteRecord(refRecord); err != nil {
|
if err := txDao.DeleteRecord(refRecord); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// no further action are needed (the reference is deleted)
|
// no further actions are needed (the reference is deleted)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +448,7 @@ func (dao *Dao) DeleteRecord(record *models.Record) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return txDao.Delete(record)
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue