diff --git a/internal/entity/photo.go b/internal/entity/photo.go index 7dbd48264..e1500e0c8 100644 --- a/internal/entity/photo.go +++ b/internal/entity/photo.go @@ -77,7 +77,7 @@ func SavePhoto(model Photo, form form.Photo, db *gorm.DB) error { model.IndexKeywords(db) - return db.Save(&model).Error + return db.Unscoped().Save(&model).Error } // BeforeCreate computes a unique UUID, and set a default takenAt before indexing a new photo diff --git a/internal/query/photo.go b/internal/query/photo.go index ad8ae8d94..d9ecbd7b0 100644 --- a/internal/query/photo.go +++ b/internal/query/photo.go @@ -347,7 +347,7 @@ func (q *Query) Photos(f form.PhotoSearch) (results []PhotoResult, err error) { // PhotoByID returns a Photo based on the ID. func (q *Query) PhotoByID(photoID uint64) (photo entity.Photo, err error) { - if err := q.db.Where("id = ?", photoID).Preload("Links").Preload("Description").First(&photo).Error; err != nil { + if err := q.db.Unscoped().Where("id = ?", photoID).Preload("Links").Preload("Description").First(&photo).Error; err != nil { return photo, err } @@ -356,7 +356,7 @@ func (q *Query) PhotoByID(photoID uint64) (photo entity.Photo, err error) { // PhotoByUUID returns a Photo based on the UUID. func (q *Query) PhotoByUUID(photoUUID string) (photo entity.Photo, err error) { - if err := q.db.Where("photo_uuid = ?", photoUUID).Preload("Links").Preload("Description").First(&photo).Error; err != nil { + if err := q.db.Unscoped().Where("photo_uuid = ?", photoUUID).Preload("Links").Preload("Description").First(&photo).Error; err != nil { return photo, err } @@ -365,7 +365,7 @@ func (q *Query) PhotoByUUID(photoUUID string) (photo entity.Photo, err error) { // PreloadPhotoByUUID returns a Photo based on the UUID with all dependencies preloaded. func (q *Query) PreloadPhotoByUUID(photoUUID string) (photo entity.Photo, err error) { - if err := q.db.Where("photo_uuid = ?", photoUUID). + if err := q.db.Unscoped().Where("photo_uuid = ?", photoUUID). Preload("Labels", func(db *gorm.DB) *gorm.DB { return db.Order("photos_labels.label_uncertainty ASC, photos_labels.label_id DESC") }).