1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2024-11-25 01:16:21 +02:00

call root record delete first

This commit is contained in:
Gani Georgiev 2022-12-09 01:49:17 +02:00
parent 9cf5e28700
commit e60f470188

View File

@ -370,6 +370,12 @@ func (dao *Dao) DeleteRecord(record *models.Record) 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)
// OR
// 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 {
return err
}
// no further action are needed (the reference is deleted)
// no further actions are needed (the reference is deleted)
continue
}
@ -442,7 +448,7 @@ func (dao *Dao) DeleteRecord(record *models.Record) error {
}
}
return txDao.Delete(record)
return nil
})
}