mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-31 01:38:14 +02:00
updated the record file handling for the before update hook too
This commit is contained in:
parent
5255515e26
commit
a1487c3235
@ -742,19 +742,37 @@ func (form *RecordUpsert) Submit(interceptors ...InterceptorFunc[*models.Record]
|
||||
|
||||
dao := form.dao.Clone()
|
||||
|
||||
// upload new files (if any)
|
||||
//
|
||||
// note: executed after the default BeforeCreateFunc and BeforeUpdateFunc hooks
|
||||
// to allow uploading AFTER the before app model hooks (eg. in case of an id change)
|
||||
// but BEFORE the actual record db persistence
|
||||
// ---
|
||||
dao.BeforeCreateFunc = func(eventDao *daos.Dao, m models.Model) error {
|
||||
if err := form.dao.BeforeCreateFunc(eventDao, m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// upload new files (if any)
|
||||
//
|
||||
// note: executed after the default BeforeCreateFunc to allow
|
||||
// executing AFTER the before app model hooks (eg. in case of an id change)
|
||||
// but BEFORE the record db persistence
|
||||
return form.processFilesToUpload()
|
||||
if m.GetId() == form.record.GetId() {
|
||||
return form.processFilesToUpload()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
dao.BeforeUpdateFunc = func(eventDao *daos.Dao, m models.Model) error {
|
||||
if err := form.dao.BeforeUpdateFunc(eventDao, m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if m.GetId() == form.record.GetId() {
|
||||
return form.processFilesToUpload()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
// ---
|
||||
|
||||
// persist the record model
|
||||
if err := dao.SaveRecord(form.record); err != nil {
|
||||
preparedErr := form.prepareError(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user