photoprism/internal/models/photo_label.go

37 lines
842 B
Go
Raw Normal View History

package models
import (
"github.com/jinzhu/gorm"
)
// Photo labels are weighted by uncertainty (100 - confidence)
type PhotoLabel struct {
LabelID uint `gorm:"primary_key;auto_increment:false"`
PhotoID uint `gorm:"primary_key;auto_increment:false"`
LabelUncertainty int
LabelSource string
Photo *Photo
Label *Label
}
func (PhotoLabel) TableName() string {
return "photos_labels"
}
func NewPhotoLabel(photoId, labelId uint, uncertainty int, source string) *PhotoLabel {
result := &PhotoLabel{
PhotoID: photoId,
LabelID: labelId,
LabelUncertainty: uncertainty,
LabelSource: source,
}
return result
}
func (m *PhotoLabel) FirstOrCreate(db *gorm.DB) *PhotoLabel {
db.FirstOrCreate(m, "photo_id = ? AND label_id = ?", m.PhotoID, m.LabelID)
return m
}