photoprism/internal/entity/photo_keyword.go
Michael Mayer 4e06deda76 Backend: Rename "models" package to "entity"
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2019-12-11 16:55:18 +01:00

27 lines
586 B
Go

package entity
import "github.com/jinzhu/gorm"
type PhotoKeyword struct {
PhotoID uint `gorm:"primary_key;auto_increment:false"`
KeywordID uint `gorm:"primary_key;auto_increment:false;index"`
}
func (PhotoKeyword) TableName() string {
return "photos_keywords"
}
func NewPhotoKeyword(photoID, keywordID uint) *PhotoKeyword {
result := &PhotoKeyword{
PhotoID: photoID,
KeywordID: keywordID,
}
return result
}
func (m *PhotoKeyword) FirstOrCreate(db *gorm.DB) *PhotoKeyword {
db.FirstOrCreate(m, "photo_id = ? AND keyword_id = ?", m.PhotoID, m.KeywordID)
return m
}